public static void ModifyCustomerCompanyName(string customerID, string newCompanyName)
 {
     using (var northwindEntities = new NorthwindEntities())
     {
         var customer = GetCustomerById(northwindEntities, customerID);
         customer.CompanyName = newCompanyName;
         northwindEntities.SaveChanges();
     }
 }
 public static void DeleteCustomer(string customerID)
 {
     using (var northwindEntities = new NorthwindEntities())
     {
         Customer customer = GetCustomerById(northwindEntities, customerID);
         northwindEntities.Customers.Remove(customer);
         northwindEntities.SaveChanges();
     }
 }
        public static string InsertNewCustomer(Customer customer)
        {
            if (customer == null)
            {
                throw new ArgumentNullException("You can not pass null as parameter");
            }

            using (var northwindEntities = new NorthwindEntities())
            {
                northwindEntities.Customers.Add(customer);
                northwindEntities.SaveChanges();
                return customer.CustomerID;
            }
        }
Exemple #4
0
        /// <summary>
        /// Problem solved by only using only one connection or introducing transactions isolation levels
        /// </summary>
        public static void Main()
        {
            var firstConection = new NorthwindEntities();
            var secondConection = new NorthwindEntities();

            var customerFromFirstCon = firstConection.Customers.First();
            var customerFromSecondCon = secondConection.Customers.First();

            Console.WriteLine("Inital Name FisrtCon: {0} - SecondCon: {1}", customerFromFirstCon.CompanyName, customerFromSecondCon.CompanyName);

            customerFromFirstCon.CompanyName = "Mercedes";

            customerFromSecondCon.CompanyName = "Jaguar";

            firstConection.SaveChanges();
            secondConection.SaveChanges();

            var result = new NorthwindEntities().Customers.First();
            Console.WriteLine("Name After Change {0}", result.CompanyName);
        }