SaveChanges没有返回实体的新副本 [英] SaveChanges not returning fresh copy of entity

查看:146
本文介绍了SaveChanges没有返回实体的新副本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ADO.Net数据上下文中调用RefreshChanges工作正常,在服务器端我更新了ChangeInterceptor中的一些内容(唯一ID,更新日期等)但我没有将更改恢复到客户端。

我查看了http流量,并没有传回实体的新副本。上下文将MergeOption设置为OverwriteChanges,但我认为这还不相关,因为实体刷新不在回复中。


ctx.MergeOption = MergeOption .OverwriteChanges;
ctx.SaveChanges ();

我错过了强制更新实体传回的东西吗?

提前感谢任何信息。

解决方案

如果您在客户端中执行更新操作,并且您正在更新服务器中的更改拦截器中的对象,那么在您重新查询实体之前,这些更改将在客户端中不可见,因为更新操作不会在响应有效负载中返回实体,因此客户端无法知道您是否在服务器中进行了其他更改。

因此,在保存更改后,您应该通过再次查询来刷新对象。

希望这有帮助。
谢谢Pratik

I have a call to RefreshChanges on the ADO.Net data context which works fine, on the server side I update a few things in the ChangeInterceptor (unique id, updated date etc) but I don't get the changes back to the client.

I've looked at the http traffic and no fresh copy of the entity is being passed back.  The context has MergeOption set to OverwriteChanges but I figure that is not yet relevant because the entity refresh is not in the reply.

ctx.MergeOption = MergeOption.OverwriteChanges;
ctx.SaveChanges();

Am I missing something which forces the updated entity to be passed back?

Thanks in advance for any info.

解决方案

If you performing a update operation in the client, and you are updating a object in your change interceptor in the server, those changes won't be visible in the client, until you re-query the entity, since update operations do not return the entity in the response payload, and hence the client has no way of knowing if you made additional changes in the server.

So after save changes, you should refresh the object by querying it again.

Hope this helps.
Thanks
Pratik


这篇关于SaveChanges没有返回实体的新副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆