-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding evaluator for IgnoreAutoIncludes #291
Comments
Hi @jeffreymonroe, Sorry for the late reply here, we missed this issue. Create specification extensions public static class SpecExtensions
{
public static ISpecificationBuilder<T> IgnoreAutoIncludes<T>(this ISpecificationBuilder<T> builder) where T : class
{
builder.Specification.Items.TryAdd("IgnoreAutoIncludes", true);
return builder;
}
} Create the evaluator for it, and hook it up to your repository public class IgnoreAutoIncludesEvaluator : IEvaluator
{
public bool IsCriteriaEvaluator { get; } = true;
public IQueryable<T> GetQuery<T>(IQueryable<T> query, ISpecification<T> specification) where T : class
{
if (specification.Items.ContainsKey("IgnoreAutoIncludes"))
{
query = query.IgnoreAutoIncludes();
}
return query;
}
}
public class AppSpecificationEvaluator : SpecificationEvaluator
{
public static AppSpecificationEvaluator Instance { get; } = new AppSpecificationEvaluator();
public AppSpecificationEvaluator() : base()
{
Evaluators.Add(new IgnoreAutoIncludesEvaluator());
}
}
public interface IRepository<T> : IRepositoryBase<T> where T : class
{
}
public class Repository<T> : RepositoryBase<T>, IRepository<T> where T : class
{
public Repository(AppDbContext dbContext) : base(dbContext, AppSpecificationEvaluator.Instance)
{
}
} And now you can simply use it from any specification. public class CustomerSpec : Specification<Customer>
{
public CustomerSpec()
{
Query.IgnoreAutoIncludes();
}
} Let me know if this helps. I'm closing the issue, feel free to re-open it if you have further questions. |
Thanks for the reply and the work you all have done with this. I will implement your suggested change. Cheers. |
I use .AutoInclude() sparingly when configuring an EF model. These are usually for relationships which utilize .HasOne().
Any thoughts on extending the Specification evaluator to add IgnoreAutoIncludes()? This would allow for loading an object graph for delete using .includes and circumventing cyclic exceptions.
The text was updated successfully, but these errors were encountered: