public List <OrderLineOption> Search(int orderId)
        {
            using (CafeKioskEntities context = (CafeKioskEntities)DbContextCreator.Context())
            {
                List <int> orderLineIds = context
                                          .OrderLines
                                          .Where(x => x.OrderID == orderId)
                                          .Select(x => x.OrderLineID)
                                          .ToList();

                var query = from x in context.OrderLineOptions
                            where orderLineIds.Contains(x.OrderLineID)
                            select new
                {
                    OrderLineOption = x,
                    OptionName      = x.Option.Name,
                    MenuName        = x.OrderLine.Menu.Name,
                    MenuPrice       = x.OrderLine.Menu.Price,
                };

                var list = query.ToList();

                foreach (var item in list)
                {
                    item.OrderLineOption.Option.Name          = item.OptionName;
                    item.OrderLineOption.OrderLine.Menu.Name  = item.MenuName;
                    item.OrderLineOption.OrderLine.Menu.Price = item.MenuPrice;
                }

                return(list.ConvertAll(x => x.OrderLineOption).ToList());
            }
        }
Beispiel #2
0
        public List <OrderLine> GetByOrderId(int OrderId)
        {
            using (var context = new CafeKioskEntities())
            {
                var query = from x in context.OrderLines
                            where x.OrderID == OrderId
                            select x;

                return(query.ToList());
            }
        }