Example #1
0
        public IEnumerable <AStore> ViewOrders(AStore store)
        {
            // lambda - lINQ (linq to objects)
            // EF Loading = Eager Loading
            var orders = _context.Stores                    //load all stores
                         .Include(s => s.Orders)            // load all orders for all stores
                         .ThenInclude(o => o.Pizzas)        // load all pizzas for all orders
                         .Where(s => s.Name == store.Name); // LINQ = lang integrated query

            // var pizzas = _context.Pizzas
            //               .Include(p => p.Crust)
            //               .Include(s => s.Size)
            //               .Include(p => p.Toppings)
            //               .Where(p => p.EntityId = order.Pizza) // looking for specific order

            // EF Explicit Loading
            var st = _context.Stores.FirstOrDefault(s => s.Name == store.Name);

            _context.Entry <AStore>(store).Collection <Order>(s => s.Orders).Load(); // load all orders+ properties for 1 store

            // sql - LINQ (ling to sql)
            // EF Lazy Loading
            var orders2 = from r in _context.Stores
                          //join ro in _context.Orders on r.EntityId == ro.StoreEntityId
                          where r.Name == store.Name
                          select r;

            return(orders.ToList());
        }
 public async Task Update(Crust item)
 {
     _context.Entry(item).State = EntityState.Modified;
     await _context.SaveChangesAsync();
 }