public static void AddCustomer(string id, string name, string title, string phone,
            string fax, string address, string postalCode, string city, string region,
            string country, string company)
        {
            using (NorthwindEntities northwind = new NorthwindEntities())
            {
                Customer customer = new Customer();
                customer.CustomerID = id;
                customer.ContactName = name;
                customer.ContactTitle = title;
                customer.Phone = phone;
                customer.Fax = fax;
                customer.Address = address;
                customer.PostalCode = postalCode;
                customer.City = city;
                customer.Region = region;
                customer.Country = country;
                customer.CompanyName = company;

                if (northwind.Customers.Find(id) == null)
                {
                    northwind.Customers.Add(customer);
                }

                northwind.SaveChanges();
            }
        }
 public static void DeleteCustomer(string id)
 {
     using (NorthwindEntities northwind = new NorthwindEntities())
     {
         Customer customerToDelete = northwind.Customers.Find(id);
         northwind.Customers.Remove(customerToDelete);
         northwind.SaveChanges();
     }
 }
        public static void ModifyCustomer(string id, string name, string title, string phone,
            string fax, string address, string postalCode, string city, string region,
            string country, string company)
        {
            using (NorthwindEntities northwind = new NorthwindEntities())
            {
                Customer customerToEdit = northwind.Customers.Find(id);
                customerToEdit.ContactName = name;
                customerToEdit.ContactTitle = title;
                customerToEdit.Phone = phone;
                customerToEdit.Fax = fax;
                customerToEdit.Address = address;
                customerToEdit.PostalCode = postalCode;
                customerToEdit.City = city;
                customerToEdit.Region = region;
                customerToEdit.Country = country;
                customerToEdit.CompanyName = company;

                northwind.Entry(customerToEdit).State = System.Data.EntityState.Modified;
                northwind.SaveChanges();
            }
        }
        public static void CreateOrder()
        {
            NorthwindEntities northwind = new NorthwindEntities();

            using (northwind)
            {
                var order = new Order()
                {
                    CustomerID = "BOTTM",
                    EmployeeID = 6,
                    ShipCity = "Sofia",
                    ShipCountry = "Bulgaria",
                    ShippedDate = DateTime.Now,
                    ShipPostalCode = "1000",
                    ShipVia = 2
                };

                var orderDetail1 = new Order_Detail()
                {
                    Order = order,
                    ProductID = 23,
                    Quantity = 10,
                    UnitPrice = 15
                };

                var orderDetail2 = new Order_Detail()
                {
                    Order = order,
                    ProductID = 27,
                    Quantity = 11,
                    UnitPrice = 19
                };

                northwind.Orders.Add(order);
                northwind.Order_Details.Add(orderDetail1);
                northwind.Order_Details.Add(orderDetail2);

                northwind.SaveChanges();
            }
        }
        public static void DoubleContext()
        {
            using (NorthwindEntities northwindEntities1 = new NorthwindEntities())
            {
                using (NorthwindEntities northwindEntities2 = new NorthwindEntities())
                {
                    Customer customerByFirstDataContext = northwindEntities1.Customers.Find("CHOPS");
                    customerByFirstDataContext.Region = "SW";

                    Customer customerBySecondDataContext = northwindEntities2.Customers.Find("CHOPS");
                    customerBySecondDataContext.Region = "SSWW";

                    northwindEntities1.SaveChanges();
                    northwindEntities2.SaveChanges();
                }
            }
        }