-
-
Notifications
You must be signed in to change notification settings - Fork 102
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
PK-FK, zero/one-one relationships with a nullable key on the primary entity causes an error when creating new objects #130
Comments
Looks like this might actually be an Entity Framework bug/misuse? With the same model and context setup as in refactorthis/GraphDiff#131 I can reproduce it in vanilla entity framework using the following:
This is conceptually equivalent to what GraphDiff is doing when constructing its internal object graph. Whether or not this is an actual bug in EF or just a misuse I'm not sure. The following version works in vanilla EF:
So the difference appears to be in whether the object graph is complete when |
Filed https://entityframework.codeplex.com/workitem/2761 as well. |
I'm not at my work machine at the moment, so I can't give the exact details, but here's the idea. I'll provide more concrete details tomorrow.
Say you have a model like this
And a context configuration like
And a test such as
Then when
SaveChanges
is called you will get an error about theSecondary
object not being able to have a null ID. Even if you make theId
property of theSecondary
object nullable, the same error will be thrown. Having a navigation property on theSecondary
object does not make a difference either.It is fully dependent on the nullability of the
Primary
object. If theId
property of thePrimary
object is eitherThen this error does not occur and the function works as expected.
Tomorrow when I'm back at work I can double check the code examples I've given here and provide more details.
Thank you!
The text was updated successfully, but these errors were encountered: