public List<CustomerViewModel> GetAllCustomers()
 {
     using (var context = new MaintenanceContext())
     {
         return context.Customers.AsNoTracking()
         .Select(c => new CustomerViewModel
         {
             CustomerId = c.CustomerId,
             Name = c.FirstName + " " + c.LastName,
             OrderCount = c.Orders.Count()
         })
         .ToList();
     }
 }
 public CustomerViewModel FindCustomer(int? id)
 {
     using (var context = new MaintenanceContext())
     {
         var cust =
           context.Customers.AsNoTracking()
                            .Select(c => new CustomerViewModel
                            {
                                CustomerId = c.CustomerId,
                                Name = c.FirstName + " " + c.LastName,
                                OrderCount = c.Orders.Count(),
                                Orders = c.Orders.Select(
                                o => new OrderViewModel
                                {
                                    OrderSource = o.OrderSource,
                                    CustomerId = o.CustomerId,
                                    OrderDate = o.OrderDate
                                }).ToList()
                            })
                             .FirstOrDefault(c => c.CustomerId == id);
         return cust;
     }
 }
コード例 #3
0
 public CustomerWithOrdersData(MaintenanceContext context)
 {
     _context = context;
 }
コード例 #4
0
 public CustomerRepository(MaintenanceContext dbContext) : base(dbContext)
 {
 }