开发者

EntityFramework v4 ApplyCurrentValues not saving referenced property changes

I have a project where I am using EFv4 to save data back to my repository. This is working as expected for the simple properties on my object but does nothing for the related objects.

For example, I have a User object and a related property Roles that is 开发者_如何学Pythona collection of Role entities.

If I update the User's lastActivity date and the Roles assigned to the user in my UI and then send the User object back to the repository to be updated I can see the new values in the User object for both lastActivity and the Roles, but when I call:

this.ObjectContext.ApplyCurrentValues(entitySet.Name.ToString(), entity);
this.ObjectContext.SaveChanges();

only the simple properties are saved like the lastActivity date, the Role changes are ignored.

Do I need to do something special update all referenced objects?

UPDATE: I was searching the web a bit more and saw that someone mentioned that ApplyCurrentValues only affects the scalar properties. Still doesn't change my original question, but it could explain why the related entities are not being updated. Microsoft's documentation makes not mention of this from what I can see.


I entered this with MSFT and it appears to be working as expected. Here is the quote from MSFT:

ApplyCurrentValues does only work with the scalar properties on a single entity. What you are trying to accomplish would be easiest with self-tracking entities. Hopefully the switch to using these entities wouldn't be too painful because you can just swpa which code generation template you are using (from the default one to the self-tracking entity one). You will not have to change your model at all, and hopefully the changes to your repository would be small.

I have logged a documentation issue to clarify what ApplyCurrentValues does. Thank you for reporting this!

Here is the referenced question:

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜