In disconnected, when you don't have a foreign key there are some gaps that EF can't work around & you have to proved extra code. Otherwise it can't see the relationship. With the FK property, it's a scalar value and easier for EF to keep track of across processes. I actually wrote my Jan 2012 Data Points column about this exact topic! EF is much easier to use when you have an FK scalar property. Otherwise many functions you expect to 'just work' can't & itf forces you to have a better understanding of what's going on and how to provide the needed info. Sorry I didn't see the missing FK before–Dec 10 '11 at 15:22.
![Entity Framework Set Id =0 When Making Post Entity Framework Set Id =0 When Making Post](http://www.uml-diagrams.org/examples/class-example-online-shopping-domain.png)
![Entity framework set id =0 when making post office Entity framework set id =0 when making post office](/uploads/1/2/5/4/125426155/998747024.png)
Saving Changes with Entity Framework 6 in ASP.NET MVC 5 Why isn’t EF saving changes? If you’re following an older tutorial for ASP.NET MVC and/or Entity Framework, but trying to apply it to the latest versions of the same, you may run into a problem where your controller’s Edit action doesn’t actually save any edits to the database. Sep 11, 2018 IDENTITYINSERT during seeding with EntityFramework 6 Code-First. So far I've been able to set the IDENTITYINSERT to On as part of the insert batch, but Entity Framework does not generate an insert statement that include the Id. This makes sense as the model thinks the database should provide the value, but in this case I want to provide the value. Model (pseudo code).
You can't simply call: context.Entry(model).State = System.Data.EntityState.Modified;The entity has to be retrieved from the context first so that EF can begin tracking it. Then you'll want to apply any changes to that entity before calling context.SaveChanges. Var entity = context.ClassAs.Find(model.Id);// set properties you want to modify on entityentity.Name = model.Name;entity.ClassB = context.ClassBs.Find(model.ClassB.Id);// other changes to entity as required.context.SaveChanges;This way EF is tracking entity and knows to apply an update against it.