pdevito3 / QueryKit

🎛️ QueryKit is a .NET library that makes it easier to query your data by providing a fluent and intuitive syntax for filtering and sorting.
Apache License 2.0
142 stars 13 forks source link

Support `hasconversion` in EF core for filter #10

Open pdevito3 opened 1 year ago

pdevito3 commented 1 year ago

Problem

When you have a VO using HasConversion like below, you need to do expressions in EF like x => x.Email == "thing" instead of x => x.Email.Value == "thing" vs using OwnsOne where you would always use the full path.

        builder.Property(x => x.Email)
            .HasConversion(x => x.Value, x => new EmailAddress(x))
            .HasColumnName("email")
            .IsRequired(false);

        builder.OwnsOne(x => x.Email, opts =>
             {
                 opts.Property(x => x.Value).HasColumnName("email");
             }).Navigation(x => x.Email)
             .IsRequired();

so ideally, the parser defaults to using the whole path, but if you pass a config object, the parser respects the path you give, so this:

        var config = new QueryKitProcessorConfiguration(config =>
        {
            config.Property<TestingPerson>(x => x.Email).HasQueryName("email");
        });

would really resolve to x => x.Email == "thing"

i started looking at this and found i can tack something like this into LeftExprParser , but then the type isn't recognized in CreateRightExpr when it calls TypeConversionFunctions, but you do need to know the type to do it right (e.g. if it's a guid or whatever)

            // Check if the nested property has a child property
            if (nestedPropertyExpression is MemberExpression memberExpression &&
                memberExpression.Expression is MemberExpression parentExpression)
            {
                return parentExpression;
            }

I think to make this work, i need to add a HasConversion() extension myself that essentially mimics the EF core method?

jovanivanovic commented 1 month ago

Hey @pdevito3, any news on this feature?

pdevito3 commented 1 month ago

Still in the backlog. Open to PRs of tie interested.