Example #1
0
        private static void SelectCustomers()
        {
            using (var context = new OnlineStoreContext())
            {
                var allCustomers = context.Customers.Skip(1).Take(1).OrderBy(c => c.Id).FirstOrDefault();

                Console.WriteLine(allCustomers.Name);


                /*foreach (var customer in allCustomers)
                 * {
                 *  Console.WriteLine(customer.Name);
                 * }
                 *
                 * var allCustomersLinq = (
                 *  from c
                 *  in context.Customers
                 *  select c.Name
                 *  );
                 * foreach (var customer in allCustomersLinq)
                 * {
                 *  Console.WriteLine(customer);
                 * }*/
            }
        }
Example #2
0
        private static void InsertCustomers()
        {
            using (var context = new OnlineStoreContext())
            {
                context.Customers.Add(new Customer()
                {
                    Name = "Sheva"
                });
                context.Add(new Customer()
                {
                    Name = "Albet"
                });
                context.AddRange(new[] { new Customer()
                                         {
                                             Name = "Masha"
                                         }, new Customer()
                                         {
                                             Name = "Dasha"
                                         } });

                context.SaveChanges();
                //Faster if you use bulkcopy(tempTable)
                //Console.WriteLine($"{customer.Name }{customer.Id }");
            }
        }
Example #3
0
        private static void QueryAndUpdateProductDisconnected()
        {
            var product = _context.Products.First();

            product.Price *= 1.1M;
            //_context.Products.Update(product);


            using (var newContext = new OnlineStoreContext())
            {
                newContext.Products.Update(product);
                newContext.SaveChanges();
            }
        }
Example #4
0
 private static void InsertProducts()
 {
     using (var context = new OnlineStoreContext())
     {
         context.Add(new Product()
         {
             Name = "IPhone X", Price = 100
         });
         context.AddRange(new[] { new Product()
                                  {
                                      Name = "MacBook Pro", Price = 100
                                  }, new Product()
                                  {
                                      Name = "IWatch", Price = 200
                                  } });
         context.SaveChanges();
     }
 }
Example #5
0
 private static void CreateOrder(string customerName, List <OrderItem> orederItems)
 {
     using (var context = new OnlineStoreContext())
     {
         context.Add(new Order()
         {
             Customer   = context.Customers.Where(x => x.Name == customerName).FirstOrDefault(),
             OrderDate  = DateTimeOffset.Now,
             Discount   = 0,
             OrderItems = new List <OrderItem>()
             {
                 new OrderItem()
                 {
                     Product = new Product()
                     {
                         Name = "SamsungTV", Price = 20000
                     }
                 }
             }
         });
     }
 }