-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
EF Core : nested entity foreign key not updating #25174
Comments
Related #18007 I believe the issue is initializing reference navigations in ctor. Specifically, when creating |
Thank you for your comment @smitpatel I tried not initializing the navigation properties inside the ctor, still I get the foreign key reference error.
|
@chin-udara - We will need a small runnable repro code to investigate this further. |
EF Team Triage: This issue is lacking enough information for us to be able to effectively triage it. In particular, it is missing the following information requested in the new issue template. Can you please provide this information?
Ideally include a complete code listing that we can run to reproduce the issue. Alternatively, you can provide a project/solution that we can run. BTW we're not just doing this to be mean 😄... we get a lot traffic on this project and it takes time to attempt to reproduce an issue based on fragments of information. In addition, our attempt is often unsuccessful as the exact conditions required to hit the issue are often not explicitly included in the code provided. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we ask that folks give us a self-contained way to reproduce an issue. For a guide on submitting good bug reports, read Painless Bug Tracking. BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions. |
Assume this table structure of a database.
There are three model classes mapping each of these tables as follows;
Assume the references are properly set in DBContext. (Database first approach; assumption is EF properly scaffold-ed the Models and the relationships. )
The following code will populate model
TableOne
and add it the context.Running this code, I get this error:
But this error does not happen when the relationship between TableThree and TableOne is removed.
Please consider the above code as a pseudo. The project is huge and I am trying to extract only the most relevant parts.
In short, the grand child, (in this case TableThree) does not get the col1:1 updated from the grand parent (in this case TableOne). But col2:1 in TableThree is properly updated with the Key from the immediate parent, TableTwo.
My understanding is that EF will update the child foreign keys automatically when inserting new entries. Is this not the case when there is a
grand parent
andparent
relationship in achild
entity?Please help. Thank you!
The text was updated successfully, but these errors were encountered: