在SaveChangesDefaultOptions = SaveChangesOptions.Batch时检索错误实体; [英] retrieving the errant entity when SaveChangesDefaultOptions = SaveChangesOptions.Batch;

查看:77
本文介绍了在SaveChangesDefaultOptions = SaveChangesOptions.Batch时检索错误实体;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我知道如何获取Response然后查看它以找到给我一个实体的Descriptor但是在我将我的保存选项设置为BATCH的情况下它只给了我最后一个对象附加用于保存(这不是导致
问题的实体)


如果我将SaveChangesOptions设置为none,那么它正确地为我提供了导致该实例的实体的描述符保存时出错。


当它设置为批处理时有没有办法做到这一点?


还是没有?

解决方案

不幸的是,可能没有办法解决这个问题。


我怀疑发生了什么(你可以确认通过使用fiddler或其他HTTP调试工具)服务器发回错误,并将'Content-Id'标头设置为它在请求中看到的最后一个内容ID(对应于上次修改的
实体)上下文)。


发生这种情况的原因是服务器可能不知道w由于单个变更集中的所有更新操作都通过单次调用IUpdatable.SaveChanges保存到提供程序(在EF的情况下,这直接将
映射到ObjectContext.SaveChanges)。 / p>

如果错误是数据服务服务器抛出的错误(例如,由于URI或有效负载格式不正确),那么我希望content-id是正确的,你可以获得正确的描述符客户端。但是对于数据库/提供者异常,你所看到的行为
可能是不可避免的。


我会做一些调查以确保,如果有什么我说过的话与您的方案匹配,请告知我们。


 


更新:


 我在本地重现了这种行为,它似乎符合我上面的解释。再次,让我知道我是否误解了你在做什么。


So I know how to take the Response and then look at it to find the Descriptor which gives me an entity but in the cases when I have my save options set to BATCH it only ever gives me the last object I attached for saving (which isn't the entity that caused the issue)

If I set the SaveChangesOptions to none than it correctly gives me the Descriptor to the entity that caused the error when saving.

Is there a way to do this when it's set to Batch?

Or no?

解决方案

Unfortunately, there may not be a way to work-around this.

What I suspect is happening (you can confirm by using fiddler or another HTTP debugging tool) is that the server is sending back the error with the 'Content-Id' header set to the last content ID it saw on the request (which corresponds to the last modified entity on the context).

The reason this happens is because the server may not know which entity caused the error, since all of the update operations in a single changeset are saved to the provider through a single call to IUpdatable.SaveChanges (in the case of EF, this maps directly to ObjectContext.SaveChanges).

If the error is one thrown by the data-services server (due to a malformed URI or payload, for instance), then I would expect the content-id to be correct, and you to get the right descriptor client-side. For database/provider exceptions however, the behavior you're seeing may be unavoidable.

I will do some investigation to make sure, and if anything I've said doesn't match with your scenario, please let me know.

 

UPDATE:

 I've reproduced this behavior locally, and it seems to match my explanation above. Again, let me know if I've misinterpreted what you're doing.


这篇关于在SaveChangesDefaultOptions = SaveChangesOptions.Batch时检索错误实体;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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