Zoi*_*nky 15 entity-framework entity-framework-core
我对我的一个实体有一个过滤器
entity.HasQueryFilter(x => !x.IsDeleted);
Run Code Online (Sandbox Code Playgroud)
我不断在日志中收到以下警告,我想将其关闭
实体“Event”已定义全局查询过滤器,并且是与实体“EventCategory”的关系所需的结束。当所需实体被过滤掉时,这可能会导致意外结果。将导航配置为可选,或者为导航中的两个实体定义匹配的查询过滤器。有关详细信息,请参阅https://go.microsoft.com/fwlink/?linkid=2131316 。
Axe*_*ate 21
如果您确定您的实体配置正确并且想要关闭该特定警告,您可以使用该DbContextOptionsBuilder.ConfigureWarnings
方法。
假设您注册DbContext
使用IServiceCollection
:
using Microsoft.EntityFrameworkCore.Diagnostics;
services.AddDbContext<MyDbContext>(options =>
{
// Other configuration here...
options.ConfigureWarnings(builder =>
{
builder.Ignore(CoreEventId.PossibleIncorrectRequiredNavigationWithQueryFilterInteractionWarning);
});
});
Run Code Online (Sandbox Code Playgroud)
请注意,这将使所有此类警告消失。
modelBuilder.Entity<EventCategory>()
.HasQueryFilter(t => !t.Event.IsDeleted);
Run Code Online (Sandbox Code Playgroud)
您应该从与事件相关的所有实体中过滤它
归档时间: |
|
查看次数: |
4709 次 |
最近记录: |