Exemple #1
0
 public List <Product> GetProducts()
 {
     using (var context = new AdventureWorkContext())
     {
         return(context.Product.AsNoTracking().ToList());
     }
 }
Exemple #2
0
        public List <SalesbyProducts> SalesbyProducts(int id)
        {
            try
            {
                using (var context = new AdventureWorkContext())
                {
                    var result = from oh in context.SalesOrderHeader
                                 join od in context.SalesOrderDetail on oh.SalesOrderID equals od.SalesOrderID
                                 join pr in context.Product on od.ProductID equals pr.ProductID
                                 where pr.ProductID.Equals(id)
                                 select new
                    {
                        pr.Name,
                        pr.ProductID,
                        oh.OrderDate.Year,
                        oh.TotalDue
                    }
                    into x
                    group x by new { x.Year, x.Name, x.ProductID }
                    into g
                        select new SalesbyProducts()
                    {
                        Total      = g.Sum(x => x.TotalDue),
                        Year       = g.Key.Year.ToString(),
                        Name       = g.Key.Name.ToUpper(),
                        ProductoId = g.Key.ProductID
                    };

                    return(result.AsNoTracking().ToList());
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
 public ProductsController(AdventureWorkContext context)
 {
     _context = context;
 }