public static void Main()
 {
     using (var db = new NorthwindEntities())
     {
         // To solve this task you need to change in the app.config file the connection string to:
         // initial catalog=NorthwindTwin
         Console.WriteLine(db.Database.CreateIfNotExists() ? "NorthwindTwin created!!" : "NorthWindTwin already exists");
     }
 }
 public static void Main()
 {
     using (var db = new NorthwindEntities())
     {
         // Comment/uncomment to check each functionality -
         Dao.InsertNewCustomersToDb(db);
         Dao.ModifyNewInsertedCustomer(db);
         Dao.DeleteNewInsertedCustomer(db);
     }
 }
Esempio n. 3
0
        public static void InsertNewCustomersToDb(NorthwindEntities db)
        {
            var newCustomer = new Customer
            {
                CustomerID = "1245",
                CompanyName = "Telerik",
            };

            db.Customers.AddOrUpdate(newCustomer);
            db.SaveChanges();
        }
 public static void Main()
 {
     using (var db = new NorthwindEntities())
     {
         foreach (var employee in db.Employees.Include("Territories"))
         {
             var correspondingTerritoriesAsString = string.Join(", ", employee.Territories
                 .Select(c => c.TerritoryDescription.Trim()));
             Console.WriteLine("{0} -> Territorries: {1}", employee.FirstName, correspondingTerritoriesAsString);
         }
     }
 }
        public static void Main()
        {
            using (var db = new NorthwindEntities())
            {
                var customers = db.Customers
                                  .Where(c => c.Orders.Any(o => o.OrderDate.Value.Year == 1997 &&
                                  o.ShipCountry == "Canada"))
                                  .Select(c => c.ContactName)
                                  .ToList();

                Console.WriteLine(string.Join(Environment.NewLine, customers));
            }
        }
        public static void Main()
        {
            using (var nw1 = new NorthwindEntities())
            {
                using (var nw2 = new NorthwindEntities())
                {
                    var rowFromFirst = nw1.Customers
                                      .First(c => c.ContactName.StartsWith("A"));
                    var rowFromSecond = nw2.Customers
                                          .First(c => c.ContactName.StartsWith("A"));

                    rowFromFirst.ContactName = "Pesho";
                    rowFromSecond.ContactName = "Gosho";

                    // Which was saved later will prevail

                    // nw1.SaveChanges();

                    // nw2.SaveChanges();
                }
            }
        }
        public static void Main()
        {
            Console.Write("Enter region of the sale (e.g. sp, bc, null works too but a lot of them will come) ");

            var region = Console.ReadLine().ToUpper();

            if (string.IsNullOrWhiteSpace(region))
            {
                region = null;
            }

            Console.Write("Enter start date (years ago, will search until now): ");
            int startDateInput;

            int.TryParse(Console.ReadLine(), out startDateInput);

            var startDate = DateTime.Now.AddYears(-startDateInput);
            var endDate = DateTime.Now;

            using (var db = new NorthwindEntities())
            {
                var orders = db.Orders
                  .Where(o => o.ShipRegion == region &&
                    o.OrderDate >= startDate &&
                    o.OrderDate <= endDate)
                  .ToList();

                if (orders.Any())
                {
                    Console.WriteLine("OrderID " +
                    string.Join(Environment.NewLine + "OrderID ", orders.Select(o => o.OrderID)));
                    Console.WriteLine("Number of orders: " + orders.Count);
                }
                else
                {
                    Console.WriteLine("No such sales");
                }
            }
        }
Esempio n. 8
0
 public static void ModifyNewInsertedCustomer(NorthwindEntities db)
 {
     var customer = db.Customers.FirstOrDefault(c => c.CustomerID == "1245");
     customer.ContactTitle = "Big Boss";
     db.SaveChanges();
 }
Esempio n. 9
0
 public static void DeleteNewInsertedCustomer(NorthwindEntities db)
 {
     var customer = db.Customers.FirstOrDefault(c => c.CustomerID == "1245");
     db.Customers.Remove(customer);
     db.SaveChanges();
 }