public JsonResult GetCustomer([FromBody] Customer cust)
        {
            //gets only the orders without recursion of customers

            List <Order>
            orders = db.Set <Customer>()

                     .Where(c => c.Id == cust.Id)
                     .Select(c => c.Orders)
                     .First()
                     .ToList();

            return(Json(orders));

            /*
             * // the following does not return json but can be patched
             *          Customer newCust = new Customer { Id=cust.Id };
             *      Customer foundCust = db.Set<Customer>().Find(newCust.Id);
             *     foundCust = db.Set<Customer>().Include(c => c.Orders).Where(c => c.Id == cust.Id).FirstOrDefault();
             *     List<Order> orders = foundCust.Orders.ToList();
             *        return Json(foundCust);
             */
        }
Beispiel #2
0
 public Repository(MvcDbContext dbContext)
 {
     _dbContext = dbContext;
     _dbSet     = dbContext.Set <TEntity>();
 }
Beispiel #3
0
 protected Repository(MvcDbContext db)
 {
     Db    = db;
     DbSet = db.Set <TEntity>();
 }