QueryKit
QueryKit copied to clipboard
Add custom whole condition alias support
Hello,
How about we get support for an alias for a custom whole condition?
Like, """AdultMale == true""" translating to """ Age >= 18 && Gender == "Male" """
This seems like business logic creeping in a bit, which seems smelly on first glance, but I'm potentially open to it.
What api would you think for setting this up in the config?
I thought of another example today that i think this would be useful for -- more like aggregate properties like creating a FullName to search for an aggregate of first name and last name. need to think through the api a bit more and this would probably be tricky to get right under the hood, but glad to have some more examples for this
Hey there! I'm not sure about business logic creeping, you might be right.
About the API, I thought we could pass an Expression<Func<T, bool>> and a string as a configuration, and then the library would know how to handle it.
var input = $"""AdultMale == true"""; //Only handles true or false
var config = new QueryKitConfiguration(config =>
{
config.Filter<Person>(x => x.Age >= 18 && x.Gender == "Male")
.HasAliasName("AdultMale");
});
The reason I came up with this, is, I can have a readonly calculated property in an entity class that is ignored on the mapping to the DB (rather than having a Computed Column). In my example, the AdultMale is the property. In this case, trying to filter directly in the "AdultMale" property would cause an exception with EF Core, with a message like
The expression could not be translated
Thus the need for it to be translated to a query that the database can actually perform.
I really need this feature
PRs are welcomed if you want to contribute
resolved in 1.4 release with derived property api