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

UseParameterizedNamesInDynamicQuery not working when parameter is converted #331

Open
SamWhitby opened this issue Dec 11, 2019 · 3 comments
Labels

Comments

@SamWhitby
Copy link

Hi,

The setting UseParameterizedNamesInDynamicQuery is not being respected when the parser has to apply a convert.

For example, i have the class with a nullable double property

internal class Person
{
    public double? FavouriteDecimalNumber { get; set; }
}

and i have the following expression that checks for equality against a specific number

var lambda = DynamicExpressionParser.ParseLambda<Person, bool>(new ParsingConfig() { UseParameterizedNamesInDynamicQuery = true }, false, "FavouriteDecimalNumber = 44.8");

The expression that is generated does not warp the value, instead it uses a constant

image

Making the property on the class Person non nullable removes the convert from the generated expression and the value then gets wrappped/parameterized as seen below
image

The problem seems to be in here where the code is only checking for the type of ConstantExpression, however in this case the expression comes through as a UnaryExpression.

I'm assuming this can be fixed by calling ConstantExpressionWrapper.Wrap before applying the cast function (but this seem to occur in quite a few places) or enhancing the ConstantExpressionWrapper.Wrap function to handle UnaryExpression types.

@StefH StefH added the bug label Dec 11, 2019
@StefH
Copy link
Collaborator

StefH commented Dec 11, 2019

@SamWhitby
Can you try version System.Linq.Dynamic.Core.1.0.20-ci-12330.nupkg from MyGet ?

@SamWhitby
Copy link
Author

Thanks for the quick response.
Unfortunately that does not fix my issue. I grabbed your branch and ran your test here and its passing under that scenario, however if you add a double property to the person object and change the value you are comparing to something like 42.4 you can see a cast is applied to the generated query and the value is not parameterized

image

I also noticed passing a nullable value as a parameter also fails as seen below, not really sure why the convert is even being applied in this case?
image

@ascott18
Copy link
Contributor

There does exist something of a workaround I've found - by explicitly instantiating the nullable constant with its corresponding nullable type constructor:

.Where("NullableDoubleId = double?(42.2)")

For me, this resulted in a correctly parameterized query.

I'll take a look at PR #332 and see what it still needs.

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

No branches or pull requests

3 participants