Repository navigation
Query: Don't read default value from databases - #21668
Merged
Merged
Conversation
Contributor
Author
|
Pending TODOs (all done)
|
maumar
reviewed
Jul 17, 2020
maumar
reviewed
Jul 18, 2020
maumar
reviewed
Jul 18, 2020
In 3.x when reading values from database, we started returning default value of expected type if the value was null in the database. That means if we needed to read int then database value was null then we got 0 back. Which is not correct as we should throw exception for the case.
The fix here is,
- All value read from databases are of nullable type as database can return null.
- Since all the bindings with database are nullable now,
- When doing member access we add null check for value types and return nullable of return type
- When doing method call we add null check for instance. All parameters we convert to original types.
- All other expressions, where they need to match the type to reconstruct the original tree, adds convert nodes.
- For translation of Single/SingleOrDefault (and friends)
- For scalar subquery
- We add coalesce with default value for SingleOrDefault
- We don't add coalesce for Single case and assume there will be non-null value coming out of database which we will try to assign.
- For non-scalar subquery
- We add default value in client side in shaper for SingleOrDefault
- We throw exception Sequence contains no elements for Single case
- Above rules are only when not returning entity type. When returning entity type, we don't have enough information to differentiate the case. Also above behavior is just side-effect of assigning values to properties which cannot take null values.
- When doing DefaultIfEmpty over a non-reference type, navigation expansion will add client side coalesce so that we can move Selector after DefaultIfEmpty
Resolves #20633
Resolves #20959
Resolves #21002
smitpatel
force-pushed
the
smit/ComplicatedMess
branch
from
July 18, 2020 03:37
b4f7045 to
4602ba3
Compare
maumar
approved these changes
Jul 18, 2020
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In 3.x when reading values from database, we started returning default value of expected type if the value was null in the database. That means if we needed to read int then database value was null then we got 0 back. Which is not correct as we should throw exception for the case.
The fix here is,
Resolves #20633
Resolves #20959
Resolves #21002