Filter By Generically By Type
This is a small feature request but I think it would be useful to the project, The ability to filter by type not Generically
Current Behavior:
this.Filter<Conversation>(c => c.Where(x => x.EmployeeUserId == userId || x.EmployerUserId == userId));
I would like to be able to filter like so:
Func<IQuerable<Conversation>, IQueryable<Conversation> conversationFilter = c => c.Where(x => x.EmployeeUserId == userId || x.EmployerUserId == userId);
this.Filter(typeof(Conversation), conversationFilter )
Hello @granthoff1107 ,
Sorry for the delay, it seems we forget to log this request.
We will try to look at it this week.
Best Regards,
Jonathan
@JonathanMagnan Any updates on this?
Hello @granthoff1107 ,
My developed look at it today and he is not sure to understand as it should already work with this code:
Func<IQueryable<EntitySimple>, IQueryable<EntitySimple>> conversationFilter = c => c.Where(x => x.ID == 1);
this.Filter(conversationFilter);
You do not have to specify the type since the generic type gets auto-resolved using the parameter specified.
Best Regards,
Jonathan
I’m aware of that. But this is a different use case. There is a possibility you want to register generically using an injected configuration.
For instance say you pass on a
Dictionary<Type, LambdaExpression>
And you want to use that to build your filters. Currently the only way to do so would be through heavy reflection.
Sorry to be more clear the code would look more like the following
Dictionary<Type, LambdaExpression> filterMap;
foreach(var filter in filterMap)
{
var filterExpression = context.Set(filter.Key).Where(filter.Value);
Filter(filter.Key, filterExpression)
}
This will generically filter from a map. Sorry this is pseudo code I’m doing on my phone but it should make sense
Hello @granthoff1107 ,
Yes, that's more clear.
You want to add a filter using an Expression or LambdaExpression. On our side, we will do the reflection and add the generic method correctly.
I will give it to one of my developers next week.
Best Regards,
Jonathan