-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Row limiting warning Skip/Take before OrderBy - GetAsync of IRepository<T> #6981
Comments
Hi
|
I call my UserRepository GetAsync (DI injected by IUserRepository)
This repository extends by IRepository
given that IUserRepository is defined as follows:
And of course within the AbpModule
The queried entity looks as follows:
The (adjusted serilog template) log then shows the warning twice, but never again unless I restart the API:
I've also tested calling ListAsync which does not show this double warning. Update/Delete I have not tested. Let me know if this helps! |
I confirm that my other IRepository<> repository shows the same warning, but then 3 times in a row. This made me to believe that the amount of warnings is related to the multiple query Include().ThenInclude() calls I do compared to HasQueryFilter additions. I used the following statement in OnModelCreating() on OneToMany children to prevent the inconsistent IsDeleted/Tenant filtering (this suppressed a warning by EF Core at startup):
This I did for 3 ManyToOne includes, which matches the amount of warnings. The reason I did the HasQueryFilter is related to this exception, which I thought I had fixed:
I think this is related. |
I think ABP framework can do nothing with this problem. |
@maliming could you provide a tip on how to implement AuditedEntity for child entities properly? (SoftDelete on root, but no cascading delete on children because of that) |
@davidzwa Are you still facing the "Using required navigation" issue? I have been working on a generic fix today - thanks for the link to the Microsoft filtering page, it helped me figure out a solution! The idea is to 'copy' the configured GlobalQueryFilter on the main entity to the nested 'target' property. Just create a public abstract class CustomAbpDbContext<TDbContext> : AbpDbContext<TDbContext> where TDbContext : DbContext
{
protected CustomAbpDbContext(DbContextOptions<TDbContext> options) : base(options) { }
protected virtual void InheritQueryFilter<TEntity, TTarget>(
ModelBuilder builder,
Expression<Func<TEntity, TTarget>> target
)
where TEntity : class, Volo.Abp.Domain.Entities.IEntity
where TTarget : class, Volo.Abp.Domain.Entities.IEntity
{
var entity = builder.Entity<TEntity>();
var parentExpression = builder.Entity<TTarget>().Metadata
?.GetQueryFilter().As<Expression<Func<TTarget, bool>>>();
if (parentExpression == null)
{
if (entity.Metadata.BaseType != null || !ShouldFilterEntity<TTarget>(entity.Metadata)) return;
parentExpression = CreateFilterExpression<TTarget>();
if (parentExpression == null) return;
}
var filter = Expression.Lambda<Func<TEntity, bool>>(
new ReplaceExpressionVisitor(parentExpression.Parameters[0], target.Body)
.Visit(parentExpression.Body),
target.Parameters[0]);
// Alternatively use this more robust method if you are using EntityFrameworkCore
// var filter = Expression.Lambda<Func<TEntity, bool>>(
// Microsoft.EntityFrameworkCore.Query.ReplacingExpressionVisitor
// .Replace(parentExpression.Parameters[0], target.Body, parentExpression.Body),
// target.Parameters[0]);
entity.HasQueryFilter(filter);
}
private class ReplaceExpressionVisitor : ExpressionVisitor
{
private readonly Expression _oldValue, _newValue;
public ReplaceExpressionVisitor(Expression oldValue, Expression newValue)
{
_oldValue = oldValue;
_newValue = newValue;
}
public override Expression Visit(Expression node)
{
if (node == _oldValue) return _newValue;
return base.Visit(node);
}
}
} |
@olicooper I did it by simply adding a HasQueryFilter on the child entity. Will definitely share that and look at your solution as well. I also tried to answer a related issue #7482 based on my knowledge (which seems limited compared to what you have made). |
Looks similar to #6179 but then in IRepository when calling GetAsync (possibly others as well). In this case my entity extends
FullAuditedEntity<Guid>
and therefore IsDeleted query filter among others is present. Or this has more to do with paging/ordering. Not sure.Can you check if this is as easy to fix as the issue mentioned above?
The text was updated successfully, but these errors were encountered: