-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Model-level Entity Filters #7413
Comments
@anpete I think it would be useful if such filters could be enabled/disabled per context instance or even modified. Is this scenario considered? |
@davidroth Yes, I was thinking of per-query granularity for disabling them. I'm not sure about modification, though. Filters will be parameterizable via variables in the same way as regular queries, which I think should capture many scenarios. I.e multitenancy. |
I think this can be achieved pretty nicely with inheritance + discriminators. You can have:
modelBuilder.Entity<ClientBase>(entity =>
{
// ....
entity.HasDiscriminator(e => e.IsDeleted)
.HasValue<Client>(false)
.HasValue<DeletedClient>(true); The downside compared to a filter would be the boilerplate code needed, but it's also a very flexible model. |
Added in b1379b1 |
@tinchou One problem with this is approach for something like soft-deletes is that it requires mutating the type that a row represents for something that normally should be just a state change. The type is normally considered immutable, similar to the primary key. This is something that in EF Core we made an explicit decision not to block (e.g. discriminator values can be accessed and usually modified), but you have to handle it with care. I am not sure it is a good idea to tie inheritance to this. |
Allow LINQ predicate expressions to be associate with Entity Types in the model. E.g.
Simple, yet powerful feature that can be used to enable many higher-level asks such as Soft-delete, multi-tenancy and filtered Include.
The text was updated successfully, but these errors were encountered: