'Understanding how to make repository queries asynchronous
I have the following LINQ query in my repository which behaves as expected:
public ICollection<Address> GetManufacterAddressesFromProductId(Guid productId)
{
return Context.Products
.First(product => product.Id == productId)
.Manufacturer
.Addresses;
}
How do I make this call async? This is my current solution, which seems... overly long?
public async Task<ICollection<Address>> GetManufacterAddressesFromProductIdAsync(Guid productId)
{
var product = await Context.Products.FirstAsync(x => x.Id == productId);
var manufacturerId = product.ManufacturerId;
return await Context.ManufacturerAddresses.Where(x => x.ManufacturerId == manufacturerId ).ToListAsync();
}
Leaves me feeling like this isn't really doing things properly, as it has to wait for the first call to complete anyway - sort of defeats the point?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
