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

Fix to #5454 - Error when using Where with reference #5796

Merged
merged 1 commit into from
Jun 17, 2016
Merged

Fix to #5454 - Error when using Where with reference #5796

merged 1 commit into from
Jun 17, 2016

Conversation

maumar
Copy link
Contributor

@maumar maumar commented Jun 16, 2016

Fixes #5454

Problem was for happening for queries with optional navigations like so:

context.Orders.Where(o => o.Customer.IsVip)

In this case Customer can be nullable, so IsVip can also be nullable. We compensate for this by introducing the following:

context.Orders.Where(o => o.Customer != null ? (bool?)o.Customer.IsVip : (bool?)null)

However, we didn't convert it back to the original type (users had to introduce those casts themselves). Without the cast, those queries were throwing compile-time exceptions that were not very informative.

Fix is to cast back to the original type requested by user:

context.Orders.Where(o => (bool)(o.Customer != null ? (bool?)o.Customer.IsVip : (bool?)null))

This still may cause runtime errors if o.Customer is actually null, but those are much more understandable now.

Also fixed compilation errors for complex Skip/Take arguments. Those are evaluated on the client for the time being.

@maumar
Copy link
Contributor Author

maumar commented Jun 16, 2016

@anpete @smitpatel

@@ -650,9 +650,22 @@ private static Expression HandleSkip(HandlerContext handlerContext)
{
var skipResultOperator = (SkipResultOperator)handlerContext.ResultOperator;

handlerContext.SelectExpression.Offset = skipResultOperator.Count;
var sqlTranslatingExpressionVisitor
Copy link
Contributor

@anpete anpete Jun 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this visitor creation into a method on HandlerContext and update all of the places we do it?. I.e. handlerContext.CreateSqlTranslatingVisitor

@anpete
Copy link
Contributor

anpete commented Jun 16, 2016

:shipit:

@anpete
Copy link
Contributor

anpete commented Jun 16, 2016

Is there a test for the Skip/Take change?

@anpete
Copy link
Contributor

anpete commented Jun 16, 2016

Reminder to also do a R# pass.

@maumar
Copy link
Contributor Author

maumar commented Jun 16, 2016

tests are: 'Optional_navigation_type_compensation_works_with_skip' and 'Optional_navigation_type_compensation_works_with_take'

Problem was for happening for queries with optional navigations like so:

context.Orders.Where(o => o.Customer.IsVip)

In this case Customer can be nullable, so IsVip can also be nullable. We compensate for this by introducing the following:

context.Orders.Where(o => o.Customer != null ? (bool?)o.Customer.IsVip : (bool?)null)

However, we didn't convert it back to the original type (users had to introduce those casts themselves). Without the cast, those queries were throwing compile-time exceptions that were not very informative.

Fix is to cast back to the original type requested by user:

context.Orders.Where(o => (bool)(o.Customer != null ? (bool?)o.Customer.IsVip : (bool?)null))

This still may cause runtime errors if o.Customer is actually null, but those are much more understandable now.

Also fixed compilation errors for complex Skip/Take arguments. Those are evaluated on the client for the time being.

CR: Andrew, Smit
@maumar maumar merged commit 7fe8981 into dev Jun 17, 2016
@maumar maumar deleted the fix5454 branch June 17, 2016 00:39
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

Successfully merging this pull request may close these issues.

None yet

3 participants