Entity Framework appears to be saving children objects before the parent object

.net c# dbcontext entity-framework entity-framework-6

Accepted Answer

Based on the navigation attributes, EF does determine the suitable order. There's still a problem. There might be a few issues.

Why do you use[DatabaseGenerated(DatabaseGeneratedOption.None)] ? Or does the database create and maintain the ids? Don't you want the database if it is?[DatabaseGenerated(DatabaseGeneratedOption.Identity)] ?

Moreover, is the agent's main key nullable? Is that accurate? Primary keys shouldn't be allowed to be null...

No, you shouldn't have to set[InverseProperty("Office")] in a typical one-to-many arrangement. This might be perplexing to EF.

1
2/16/2017 4:28:38 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow