public async Task<Employee> GetAsync(int id) { using (var context = new AdventureWorksContext()) { return await context.Employees .Where(e => e.Id == id) .FirstOrDefaultAsync() .ConfigureAwait(false); } }
public async Task<Person> GetAsync(int id) { using (var context = new AdventureWorksContext()) { return await context.People .Where(p => p.Id == id) .FirstOrDefaultAsync() .ConfigureAwait(false); } }
public async Task<Customer> GetAsync(int id) { using (var context = new AdventureWorksContext()) { return await context.Customers .Include(c => c.Person) .Where(c => c.CustomerId == id) .FirstOrDefaultAsync() .ConfigureAwait(false); } }
public async Task<ICollection<SalesOrderHeader>> GetTopTenSalesOrdersAsync() { using (var context = new AdventureWorksContext()) { return await context.SalesOrders .Include(soh => soh.Customer.Person) .Include(soh => soh.SalesPerson) .OrderByDescending(soh => soh.TotalDue) .Take(10) .ToListAsync() .ConfigureAwait(false); } }
public async Task<ICollection<SalesPersonTotalSales>> GetTopTenSalesPeopleAsync() { using (var context = new AdventureWorksContext()) { return await context.SalesOrders .Where(soh => soh.SalesPerson != null) .GroupBy(soh => soh.SalesPerson) .OrderByDescending(g => g.Sum(soh => soh.TotalDue)) .Take(10) .Select(g => new SalesPersonTotalSales() { SalesPerson = g.Key, TotalSales = g.Sum(soh => soh.TotalDue) }) .ToListAsync() .ConfigureAwait(false); } }