-
Notifications
You must be signed in to change notification settings - Fork 256
Expand file tree
/
Copy pathIncludeStringEvaluator.cs
More file actions
29 lines (24 loc) · 881 Bytes
/
IncludeStringEvaluator.cs
File metadata and controls
29 lines (24 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
namespace Ardalis.Specification.EntityFrameworkCore;
public sealed class IncludeStringEvaluator : IEvaluator
{
private IncludeStringEvaluator() { }
public static IncludeStringEvaluator Instance { get; } = new();
public bool IsCriteriaEvaluator => false;
/// <inheritdoc/>
public IQueryable<T> GetQuery<T>(IQueryable<T> query, ISpecification<T> specification) where T : class
{
if (specification is Specification<T> spec)
{
if (spec.OneOrManyIncludeStrings.IsEmpty) return query;
if (spec.OneOrManyIncludeStrings.SingleOrDefault is { } includeString)
{
return query.Include(includeString);
}
}
foreach (var includeString in specification.IncludeStrings)
{
query = query.Include(includeString);
}
return query;
}
}