Skip to content
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

Closed
anpete opened this issue Jan 14, 2017 · 6 comments
Closed

Model-level Entity Filters #7413

anpete opened this issue Jan 14, 2017 · 6 comments
Assignees

Comments

@anpete
Copy link
Contributor

anpete commented Jan 14, 2017

Allow LINQ predicate expressions to be associate with Entity Types in the model. E.g.

modelBuilder.Entity<Customer>().HasFilter(c => !c.IsDeleted); // soft-delete!

Simple, yet powerful feature that can be used to enable many higher-level asks such as Soft-delete, multi-tenancy and filtered Include.

@anpete anpete self-assigned this Jan 14, 2017
@anpete anpete added this to the 2.0.0 milestone Jan 14, 2017
@davidroth
Copy link
Contributor

davidroth commented Jan 20, 2017

@anpete I think it would be useful if such filters could be enabled/disabled per context instance or even modified.
If I take the soft-deletion as an example, it is quite common that there is some kind of toggle/switch which enables/disables hiding soft deleted entities in an application/view.

Is this scenario considered?

@anpete
Copy link
Contributor Author

anpete commented Jan 20, 2017

@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.

@colltoaction
Copy link
Contributor

I think this can be achieved pretty nicely with inheritance + discriminators. You can have:

         ClientBase
   +--------+  +-----------+
   |                       |
   v                       v
Client               DeletedClient
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.

@ajcvickers ajcvickers modified the milestones: 2.0.0-preview1, 2.0.0 Apr 19, 2017
@anpete anpete added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label May 8, 2017
@anpete anpete modified the milestones: 2.0.0-preview1, 2.0.0 May 8, 2017
@anpete
Copy link
Contributor Author

anpete commented May 8, 2017

Added in b1379b1

@anpete anpete closed this as completed May 8, 2017
@ajcvickers
Copy link
Contributor

Discussed with @divega and it looks like we have two issues tracking this (and a third for DefiningQuery), so closing this as a duplicate of the older issue--that is #5774

@ajcvickers ajcvickers added closed-duplicate and removed closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement labels May 9, 2017
@ajcvickers ajcvickers removed this from the 2.0.0-preview1 milestone May 9, 2017
@divega
Copy link
Contributor

divega commented May 9, 2017

I think this can be achieved pretty nicely with inheritance + discriminators

@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.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants