Closed
Description
This article implies that if I have 10 entities which have the same field "IsDeleted" I need to copy-paste the filter 10 times.
Basic OOP expects to have a single base entity with the field and the rule applied on the base level.
At the moment I greatly struggle with EF Core trying to do exactly this and nowhere can find applicable article.
In my case a large number of 3rd pty tables having StatusId field, which I mage though basic abstract class HasStatus.
The best so far is that I manage to enumarate though all entities but can't apply a filter, as there is no generic to accept the base type. HasQueryFilter accepts LambdaExpression, which is a bummer.
foreach (var entity in modelBuilder.Model.FindLeastDerivedEntityTypes(typeof(HasStatus)))
{
modelBuilder.Entity(entity.ClrType)
.HasQueryFilter(t => t.StatusID == 1);
}
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: b7c9bd3e-4b99-9acf-48d8-e47bc53eb54e
- Version Independent ID: 220e0a6c-d227-956a-d27a-7c88804f770c
- Content: Global Query Filters - EF Core
- Content Source: entity-framework/core/querying/filters.md
- Product: entity-framework
- Technology: entity-framework-core
- GitHub Login: @maumar
- Microsoft Alias: avickers