EF 4.1 SaveChanges not updating navigation or reference properties

主宰稳场 提交于 2019-12-03 10:11:31
Carbosound1

Try this:

  context.Entry(contact.USState ).State = EntityState.Modified; //////
Syed Wajeeh Bukhari

Assuming your DAL objects/Collection are from Entity Framework, do this;

Contact.ContactTypes.Load();

This will refresh the related coltactTypes list from the underlying source.

Hope this helps.

The code provided might not be enough. Better to see the code how the navigation properties were added in the code. Because even though the parent class was marked as modified, it doesn't mean the related navigation properties are marked as Added or modified as well. The quickest way is to turn on the debugger at where .SaveChanges was called, and then look at the context variable, look into "Local" properties, and then whether the navigation properties are there, also whether their modalstate was added or modified, then it will be much easier to tell what need to be done.

am sure more code will help better determening the problem,especially the code for the model binding going on. but one thing i think you are already familiar with is that you need to access those navigation properties (Somehow) so EF will be able to automatically load them.because you marked your nav-properties as virtual you are allowing EF to Create proxies and override your nav-properties to allow Lazy Loading.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!