Skip to content

Commit

Permalink
Added WithSpecification overload for specifications with Select. (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
fiseni authored Jun 23, 2022
1 parent c549a57 commit e4445af
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ namespace Ardalis.Specification.EntityFramework6
{
public static class DbSetExtensions
{
public static async Task<List<TSource>> ToListAsync<TSource>(this DbSet<TSource> source, ISpecification<TSource> specification, CancellationToken cancellationToken = default) where TSource : class
public static async Task<List<TSource>> ToListAsync<TSource>(
this DbSet<TSource> source,
ISpecification<TSource> specification,
CancellationToken cancellationToken = default)
where TSource : class
{
var result = await SpecificationEvaluator.Default.GetQuery(source, specification).ToListAsync(cancellationToken);

Expand All @@ -17,7 +21,11 @@ public static async Task<List<TSource>> ToListAsync<TSource>(this DbSet<TSource>
: specification.PostProcessingAction(result).ToList();
}

public static async Task<IEnumerable<TSource>> ToEnumerableAsync<TSource>(this DbSet<TSource> source, ISpecification<TSource> specification, CancellationToken cancellationToken = default) where TSource : class
public static async Task<IEnumerable<TSource>> ToEnumerableAsync<TSource>(
this DbSet<TSource> source,
ISpecification<TSource> specification,
CancellationToken cancellationToken = default)
where TSource : class
{
var result = await SpecificationEvaluator.Default.GetQuery(source, specification).ToListAsync(cancellationToken);

Expand All @@ -26,7 +34,21 @@ public static async Task<IEnumerable<TSource>> ToEnumerableAsync<TSource>(this D
: specification.PostProcessingAction(result);
}

public static IQueryable<TSource> WithSpecification<TSource>(this IQueryable<TSource> source, ISpecification<TSource> specification, ISpecificationEvaluator evaluator = null) where TSource : class
public static IQueryable<TSource> WithSpecification<TSource>(
this IQueryable<TSource> source,
ISpecification<TSource> specification,
ISpecificationEvaluator evaluator = null)
where TSource : class
{
evaluator = evaluator ?? SpecificationEvaluator.Default;
return evaluator.GetQuery(source, specification);
}

public static IQueryable<TResult> WithSpecification<TSource, TResult>(
this IQueryable<TSource> source,
ISpecification<TSource, TResult> specification,
ISpecificationEvaluator evaluator = null)
where TSource : class
{
evaluator = evaluator ?? SpecificationEvaluator.Default;
return evaluator.GetQuery(source, specification);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ namespace Ardalis.Specification.EntityFrameworkCore
{
public static class DbSetExtensions
{
public static async Task<List<TSource>> ToListAsync<TSource>(this DbSet<TSource> source, ISpecification<TSource> specification, CancellationToken cancellationToken = default) where TSource : class
public static async Task<List<TSource>> ToListAsync<TSource>(
this DbSet<TSource> source,
ISpecification<TSource> specification,
CancellationToken cancellationToken = default)
where TSource : class
{
var result = await SpecificationEvaluator.Default.GetQuery(source, specification).ToListAsync(cancellationToken);

Expand All @@ -17,7 +21,11 @@ public static async Task<List<TSource>> ToListAsync<TSource>(this DbSet<TSource>
: specification.PostProcessingAction(result).ToList();
}

public static async Task<IEnumerable<TSource>> ToEnumerableAsync<TSource>(this DbSet<TSource> source, ISpecification<TSource> specification, CancellationToken cancellationToken = default) where TSource : class
public static async Task<IEnumerable<TSource>> ToEnumerableAsync<TSource>(
this DbSet<TSource> source,
ISpecification<TSource> specification,
CancellationToken cancellationToken = default)
where TSource : class
{
var result = await SpecificationEvaluator.Default.GetQuery(source, specification).ToListAsync(cancellationToken);

Expand All @@ -26,7 +34,21 @@ public static async Task<IEnumerable<TSource>> ToEnumerableAsync<TSource>(this D
: specification.PostProcessingAction(result);
}

public static IQueryable<TSource> WithSpecification<TSource>(this IQueryable<TSource> source, ISpecification<TSource> specification, ISpecificationEvaluator? evaluator = null) where TSource : class
public static IQueryable<TSource> WithSpecification<TSource>(
this IQueryable<TSource> source,
ISpecification<TSource> specification,
ISpecificationEvaluator? evaluator = null)
where TSource : class
{
evaluator = evaluator ?? SpecificationEvaluator.Default;
return evaluator.GetQuery(source, specification);
}

public static IQueryable<TResult> WithSpecification<TSource, TResult>(
this IQueryable<TSource> source,
ISpecification<TSource, TResult> specification,
ISpecificationEvaluator? evaluator = null)
where TSource : class
{
evaluator = evaluator ?? SpecificationEvaluator.Default;
return evaluator.GetQuery(source, specification);
Expand Down

0 comments on commit e4445af

Please sign in to comment.