Skip to content
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

Add custom whole condition alias support #38

Open
AlexMKotcz opened this issue Apr 18, 2024 · 5 comments
Open

Add custom whole condition alias support #38

AlexMKotcz opened this issue Apr 18, 2024 · 5 comments

Comments

@AlexMKotcz
Copy link
Contributor

Hello,

How about we get support for an alias for a custom whole condition?

Like, """AdultMale == true""" translating to """ Age >= 18 && Gender == "Male" """

@pdevito3
Copy link
Owner

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?

@pdevito3
Copy link
Owner

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

@AlexMKotcz
Copy link
Contributor Author

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.

@jveko
Copy link

jveko commented May 24, 2024

I really need this feature

@pdevito3
Copy link
Owner

PRs are welcomed if you want to contribute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants