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

Entity Framework String gt lt gte lte #58

Open
cherrydev opened this issue Mar 19, 2015 · 1 comment
Open

Entity Framework String gt lt gte lte #58

cherrydev opened this issue Mar 19, 2015 · 1 comment

Comments

@cherrydev
Copy link

If a querystring is parsed that contains < > <= >= operators on two strings, the expression parser passes it through unchanged, which results in an error. Underneath, in SQL, strings can be compared ordinally with these operators, but EntityFramework requires them to be expressed as:

operand1.CompareTo(operand2) < 0
operand1.CompareTo(operand2) > 0
operand1.CompareTo(operand2) <= 0
operand1.CompareTo(operand2) >= 0

Unfortunately I cannot figure out how to use Configuration to replace GreaterThanNode et all with custom versions that can create these expressions. Am I correct in saying that CustomNodeMappings can't replace existing node types in this sort of way?

In any case, making it an extension isn't really important because converting these operators to CompareTo for strings is probably always going to be more useful than the error that we'd get otherwise, even if the underlying provider doesn't always have direct support for CompareTo like EF does.

@cherrydev
Copy link
Author

I've written a patch that creates a new OrdinalNode abstract class that has a BuildOrdinalExpression method that has the same signature of BuildQueryExpression except that it takes an ExpressionType as an additional parameter. It then checks to see if both operands are strings and if so, returns a CompareTo expression, otherwise it calls through to ApplyEnsuringNullablesHaveValues unchanged.
Would you use that?

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

1 participant