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

Query: Materialize results of FirstOrDefault in subquery only when th… #18693

Merged
merged 1 commit into from
Nov 1, 2019

Conversation

smitpatel
Copy link
Contributor

…ere are rows

Issue: When we generate translation for subquery.FirstOrDefault() using Left join, we get null in values when there is no associated record.
Then we try to create result with default values rather than returning default of result type.

Fix: Whenever we go through path where we are adding subquery.FirstOrDefault in projection, we inject 1 as dummy column. If we see 1 in result then only we materialize the object else we return default of the type.

  • For entityTypes this is not needed because we return null if key values are null.
  • For scalar which is server eval (i.e. only 1 column), we generate projectionBinding using resultType so we will get correct default back.
  • For scalar result which is client eval, we inject 1 into client projections.
  • For non scalar results (anonymous/nominal types), in client/server eval case, we inject 1 into projection/projectionMapping.

Resolves #17287

…ere are rows

Issue: When we generate translation for subquery.FirstOrDefault() using Left join, we get null in values when there is no associated record.
Then we try to create result with default values rather than returning default of result type.

Fix: Whenever we go through path where we are adding subquery.FirstOrDefault in projection, we inject 1 as dummy column. If we see 1 in result then only we materialize the object else we return default of the type.
- For entityTypes this is not needed because we return null if key values are null.
- For scalar which is server eval (i.e. only 1 column), we generate projectionBinding using resultType so we will get correct default back.
- For scalar result which is client eval, we inject 1 into client projections.
- For non scalar results (anonymous/nominal types), in client/server eval case, we inject 1 into projection/projectionMapping.

Resolves #17287
@smitpatel smitpatel merged commit 43954b9 into release/3.1 Nov 1, 2019
@smitpatel smitpatel deleted the smit/firstOrDefault branch November 1, 2019 22:31
@smitpatel
Copy link
Contributor Author

cc: @Pilchie

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.

Query: FirstOrDefault on anonymous type in subquery gives wrong results
3 participants