Skip to content

Fix querying with delayed entity insert #2416

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

Closed
wants to merge 6 commits into from

Conversation

galamai
Copy link

@galamai galamai commented Jun 9, 2020

Fix #2414

@fredericDelaporte fredericDelaporte changed the title #2414 fix error when query with delayed insert entity in where expres… Fix querying with delayed entity insert Jun 14, 2020
Log.Debug("binding 0 to parameter: {0}", index);
}

st.Parameters[index].Value = 0;
Copy link
Member

Choose a reason for hiding this comment

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

This assumes the identifier is compatible with an int, and this assumes 0 is not a valid value for it. This will be wrong in many cases.

Copy link
Author

Choose a reason for hiding this comment

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

DelayedPostInsertIdentifier exists only for auto-increment fields, so I believe that the value 0 in this case is correct

Copy link
Author

Choose a reason for hiding this comment

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

I compared this behavior with entity framework core 3 comparison by reference for an entity that is not yet stored in the table returns exactly parameter 0 in all cases

Copy link
Member

@bahusoid bahusoid Jun 15, 2020

Choose a reason for hiding this comment

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

What if entity.Id is not 0 for transient entity and for instance it's -1?

DelayedPostInsertIdentifier exists only for auto-increment fields, so I believe that the value 0 in this case is correct

Not true for the following SQL Server table:

CREATE TABLE Entity
(  
Id int IDENTITY(0,1), -- start from 0
Name varchar (20) 
 );  

@hazzik hazzik closed this Aug 30, 2022
@hazzik
Copy link
Member

hazzik commented Aug 30, 2022

With changes from #3043 now tests fail.

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

Successfully merging this pull request may close these issues.

Error when query with delayed insert entity in where expression
4 participants