Пример #1
0
        private static void AddMultipleCustomers()
        {
            var cust1 = new Customer
            {
                FirstName = "Pete",
                LastName = "Townsend",
                Email = "*****@*****.**",
                Phone = "613 555-2355",
                Fax = "867-598"
            };

            var cust2 = new Customer
            {
                FirstName = "John",
                LastName = "Entwistle",
                Email = "*****@*****.**",
                Phone = "613 444-5555",
                Fax = "345-5909"
            };

            using (var context = new CustomerContext())
            {
                context.Database.Log = Console.WriteLine;
                context.Customers.AddRange(new List<Customer> {cust1, cust2});
                context.SaveChanges();

            }
        }
Пример #2
0
        private static void AddCustomerandOrders()
        {
            var cust = new Customer
            {
                FirstName = "Paul",
                LastName = "Oakenfeld",
                Email = "*****@*****.**",
                Phone = "613 876-5555",
                Fax = "867-0987"
            };

            var order1 = new Order
            {
                 ProductName = "Sunglasses"
            };

            var order2 = new Order
            {
                ProductName = "Shoes"
            };

            using (var context = new CustomerContext())
            {
                context.Database.Log = Console.WriteLine;
                context.Customers.Add(cust);
                cust.CustomerOrders.Add(order1);
                cust.CustomerOrders.Add(order2);
                context.SaveChanges();

            }
        }
 public void SaveUpdatedCustomer(Customer cust)
 {
     using (var context = new CustomerContext())
     {
         context.Entry(cust).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
 public void SaveNewCustomer(Customer cust)
 {
     using(var context = new CustomerContext ())
     {
         context.Customers.Add(cust);
         context.SaveChanges();
     }
 }
Пример #5
0
        private static void AddCustomer()
        {
            var cust = new Customer {
                FirstName = "Patrick",
                LastName = "Clarke",
                Email = "*****@*****.**",
                Phone = "613 555-5555",
                Fax = "867-5309"
            };

            using(var context = new CustomerContext())
            {
                context.Database.Log = Console.WriteLine;
                context.Customers.Add(cust);
                context.SaveChanges();

            }
        }