QueryKit icon indicating copy to clipboard operation
QueryKit copied to clipboard

Support `hasconversion` in EF core for filter

Open pdevito3 opened this issue 2 years ago • 2 comments
trafficstars

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?

pdevito3 avatar Jul 24 '23 03:07 pdevito3

Hey @pdevito3, any news on this feature?

jovanivanovic avatar Jun 14 '24 09:06 jovanivanovic

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

pdevito3 avatar Jun 14 '24 11:06 pdevito3