Ejemplo n.º 1
0
 public static void ModifyCustomerCompanyName(string customerID, string newCompanyName)
 {
     using (var northwindEntities = new NorthwindEntities())
     {
         var customer = GetCustomerById(northwindEntities, customerID);
         customer.CompanyName = newCompanyName;
         northwindEntities.SaveChanges();
     }
 }
Ejemplo n.º 2
0
 public static void DeleteCustomer(string customerID)
 {
     using (var northwindEntities = new NorthwindEntities())
     {
         Customer customer = GetCustomerById(northwindEntities, customerID);
         northwindEntities.Customers.Remove(customer);
         northwindEntities.SaveChanges();
     }
 }
Ejemplo n.º 3
0
        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;
            }
        }
Ejemplo n.º 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);
        }