|
|
|
@ -43,25 +43,34 @@ namespace Infrastructure.Data |
|
|
|
|
|
|
|
public IEnumerable<T> List(ISpecification<T> spec) |
|
|
|
{ |
|
|
|
// fetch a Queryable that includes all expression-based includes
|
|
|
|
var queryableResultWithIncludes = spec.Includes |
|
|
|
.Aggregate(_dbContext.Set<T>().AsQueryable(), |
|
|
|
(current, include) => current.Include(include)); |
|
|
|
|
|
|
|
// modify the IQueryable to include any string-based include statements
|
|
|
|
var secondaryResult = spec.IncludeStrings |
|
|
|
.Aggregate(queryableResultWithIncludes, |
|
|
|
(current, include) => current.Include(include)); |
|
|
|
|
|
|
|
// return the result of the query using the specification's criteria expression
|
|
|
|
return secondaryResult |
|
|
|
.Where(spec.Criteria) |
|
|
|
.AsEnumerable(); |
|
|
|
} |
|
|
|
public async Task<List<T>> ListAsync(ISpecification<T> spec) |
|
|
|
{ |
|
|
|
// fetch a Queryable that includes all expression-based includes
|
|
|
|
var queryableResultWithIncludes = spec.Includes |
|
|
|
.Aggregate(_dbContext.Set<T>().AsQueryable(), |
|
|
|
(current, include) => current.Include(include)); |
|
|
|
|
|
|
|
// modify the IQueryable to include any string-based include statements
|
|
|
|
var secondaryResult = spec.IncludeStrings |
|
|
|
.Aggregate(queryableResultWithIncludes, |
|
|
|
(current, include) => current.Include(include)); |
|
|
|
|
|
|
|
// return the result of the query using the specification's criteria expression
|
|
|
|
return await secondaryResult |
|
|
|
.Where(spec.Criteria) |
|
|
|
.ToListAsync(); |
|
|
|
|