add FirstAsync in respository (#370)
* add FirstAsync in respository * use new FirstOrDefaultAsync() method from repository
This commit is contained in:
@@ -61,6 +61,16 @@ namespace Microsoft.eShopWeb.Infrastructure.Data
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<T> FirstAsync(ISpecification<T> spec)
|
||||
{
|
||||
return await ApplySpecification(spec).FirstAsync();
|
||||
}
|
||||
|
||||
public async Task<T> FirstOrDefaultAsync(ISpecification<T> spec)
|
||||
{
|
||||
return await ApplySpecification(spec).FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
private IQueryable<T> ApplySpecification(ISpecification<T> spec)
|
||||
{
|
||||
return SpecificationEvaluator<T>.GetQuery(_dbContext.Set<T>().AsQueryable(), spec);
|
||||
|
||||
Reference in New Issue
Block a user