-
-
Notifications
You must be signed in to change notification settings - Fork 85
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
filtering data base on user premession or roles #117
Comments
First of all, I'm not sure what the GlobalFilter class or ApplyFilter method are. So I'm going to assume GlobalFilter is derived from DbContext and the ApplyFilter method is called from inside the OnModelCreating() method. I also don't know the type of the 'AllowedRolesPremissionJsonString' property. From the name of it, it sounds like it's a string. But you are referencing a ".Contains" property. If it is a string, then that will be a problem since you are passing a reference to the Contains method when the .Any() is going to be expecting a string. Also, you can't access a private method to retrieve the value for the "roles" parameter. When the expression value is needed, it will fail to evaluate that because it will not have a reference to the "GlobalFilters" instance. The proper way to handle that is to reference your DbContext derived class as described here: https://github.com/jcachat/EntityFramework.DynamicFilters#parameter-expressions. So based on my assumptions above, I THINK your filter should look like this:
|
GlobalFilter is a base class that i will inject a list from it to my dbcontext from its constructor
And any drived class applies its own logic
thanks . |
any way i need a way to decouple my db context from system requirement logics
i am not good in english sorry about Misspellings and grammar thank you again. |
i wrote this for sake of testing but the same problem exists : example of AllowedRolesPremissionJsonString value ::
and what i got is ::
|
any idea ?? i still have that problem |
I don't know what's wrong with the .Any() clause. That is supported. Look in the unit tests at the ChildCollectionFiltersTests.cs. There are a couple of tests there for .Any(). Maybe experiment with those and try to plug in your specific entities (as much as possible) to see if you can reproduce it there. string.Contains() is not supported at the moment. That only works on an IEnumerable. That is something I can fix but that will only fix your .Contains("Hello") attempt. Also, I think I see what you were trying to do in your original filter. Where you have this clause:
I don't think that syntax can be supported and might be why it's complaining about needing a collection result type. But once I add support for stirng.Contains() in the filter linq, this might work:
I'll try to get that done in the next day or 2. |
I just pushed out an update (v 2.10.0) that adds support for string.Contains(). But, after another look, I don't think this is going to work at all. If you create the filter like this:
that will create a subquery that attempts to evaluate this portion of that query:
The problem there is that it's accessing the outer table ('x' in the linq query) which would not be valid sql since the inner sql query will not have any reference to the outer "x" entity set. I also don't know if a valid query can be created against the parameter "roles" - it may only work on an entity collection. |
Can you add support for filter with claim |
ex message:
The text was updated successfully, but these errors were encountered: