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'm having a strange problem with new global query filters (HasQueryFilter). My code is complicated since I'm developing an application framework. So, I will share the related code.
IsSoftDeleteFilterEnabled, IsMayHaveTenantFilterEnabled, CurrentTenantId... are properties of my dbcontext.
Problem
The problem is !IsSoftEnabled (and other boolean flags) is not properly working. It caches the first dbcontext instance and never called again for later dbcontext instances. But CurrentTenantId property is properly called (there is interesting thing here: It's called one more time for each different query, before the actual query - I suppose it's for caching the query, but no problem).
The interesting this is that, when I compare IsSoftEnabled value with a property of the entity, it starts working. I suppose when we compare it via an entity property (like IsSoftDeleteFilterEnabled == e.IsDeleted || !((ISoftDelete) e).IsDeleted - this is just a stupid example) it does not grab value, but gets the expression property.
For this reason, I can not properly create a boolean flag to disable/enable a filter individually.
The text was updated successfully, but these errors were encountered:
e =>!IsSoftDeleteFilterEnabled||!((ISoftDelete)e).IsDeleted
IsSoftDeleteFilterEnabled is only called one time, not for all queries. It somehow caches the value (or dbcontext instance)
But this works:
e =>!((ISoftDelete)e).IsDeleted||((ISoftDelete)e).IsDeleted!= IsSoftDeleteFilterEnabled
By the magic of logical expressions, both expressions are actually identical (you can proove it) and I'm using this workaround. However I'm not sure the second one produce good & optimum SQL.
Hi,
I'm having a strange problem with new global query filters (HasQueryFilter). My code is complicated since I'm developing an application framework. So, I will share the related code.
What I'm achiving here to combine soft delete and multitenant filters based on implemented interfaces of entities, as can be understood easily.
I'm using this PredicateBuilder (http://www.albahari.com/nutshell/predicatebuilder.aspx) to create the expression.
IsSoftDeleteFilterEnabled
,IsMayHaveTenantFilterEnabled
,CurrentTenantId
... are properties of my dbcontext.Problem
The problem is
!IsSoftEnabled
(and other boolean flags) is not properly working. It caches the first dbcontext instance and never called again for later dbcontext instances. ButCurrentTenantId
property is properly called (there is interesting thing here: It's called one more time for each different query, before the actual query - I suppose it's for caching the query, but no problem).The interesting this is that, when I compare
IsSoftEnabled
value with a property of the entity, it starts working. I suppose when we compare it via an entity property (likeIsSoftDeleteFilterEnabled == e.IsDeleted || !((ISoftDelete) e).IsDeleted
- this is just a stupid example) it does not grab value, but gets the expression property.For this reason, I can not properly create a boolean flag to disable/enable a filter individually.
The text was updated successfully, but these errors were encountered: