You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to have the ability to be able to configure on a per DbSet basis, multiple query filters and be able to disable them individually. As opposed to the current all-or-none design, as I have some filters I would like to setup as permanent and some that could be disabled at runtime.
Motivation/Problem
When developing a multi-tenant database with a single instance with discriminator column (ex: TenantId) as recommended here, I would like to have other query filters that can be disabled at runtime without disabling a query filter that is required for multi-tenancy.
Consider the following configuration using the current latest version of EntityFramework Core
With this example, if I wanted to retrieve records regardless of the IsActive value, I would have to disable the query filter which would also disable by always required multi-tenant query filter. The only alternative is to ensure that the Linq statement is always using the multi-tenant predicate. Not ideal as this could lead to bugs and data corruption between tenants.
varresult=await context.Companies.IgnoreQueryFilters().ToListAsync();// this would now get me all data across all tenants
Preferred Solution
The preferred solution involves:
Using a single database instance
Adding a discriminator column to all tables
Configuring multiple query filters (still per DbSet) but with a key
varresult=await context.Companies.IgnoreQueryFilter("ActiveOnly");// now the data is restricted to the current multi-tenant
Assumptions
With the given solution a few design assumptions would need to be discussed
The inner list that tracks the predicates to key would either need to overwrite duplicates OR treat it as a hash and throw exceptions on duplicate insert
When IgnoreQueryFilter(string key) is called and no matching query filter is configured, then compose the LINQ query as if that query filter was not registered in the first place
If more than one query filter needs to be disabled then chained calls to IgnoreQueryFilter(string key) would be allowed.
The text was updated successfully, but these errors were encountered:
@jasonayerp as far as I can tell, your requests are already tracked by the above two issues; other possible improvements to query filters are tracked by #21459.
I'll go ahead and close this, but if you think there's something not already covered by the other issues, please post back and we can reopen.
Feature Request
I would like to have the ability to be able to configure on a per
DbSet
basis, multiple query filters and be able to disable them individually. As opposed to the current all-or-none design, as I have some filters I would like to setup as permanent and some that could be disabled at runtime.Motivation/Problem
When developing a multi-tenant database with a single instance with discriminator column (ex:
TenantId
) as recommended here, I would like to have other query filters that can be disabled at runtime without disabling a query filter that is required for multi-tenancy.Consider the following configuration using the current latest version of EntityFramework Core
With this example, if I wanted to retrieve records regardless of the
IsActive
value, I would have to disable the query filter which would also disable by always required multi-tenant query filter. The only alternative is to ensure that the Linq statement is always using the multi-tenant predicate. Not ideal as this could lead to bugs and data corruption between tenants.Preferred Solution
The preferred solution involves:
Consider the following proposal:
This way I can ignore only the predicates I want:
Assumptions
With the given solution a few design assumptions would need to be discussed
IgnoreQueryFilter(string key)
is called and no matching query filter is configured, then compose the LINQ query as if that query filter was not registered in the first placeIgnoreQueryFilter(string key)
would be allowed.The text was updated successfully, but these errors were encountered: