通过 LINQ 编辑 WCF 数据服务的数据
我创建了一个小型 WCF 数据服务,我可以毫无问题地添加/检索数据。
我对这个集合“Household”有一套,拥有所有权利:
config.SetEntitySetAccessRule("HouseHold", EntitySetRights.All);
问题是我无法编辑:
HouseHold houseHold = entities.HouseHold.Where(h => h.IDHouseHold == varContainingAnExistingId).FirstOrDefault();
houseHold.LastName = "LastName" + DateTime.Now;
entities.SaveChanges();
我没有任何例外,我的数据只是没有在数据库中更新。
我错过了什么吗?我应该做更多的事情来保存我的更改吗?
(我的断点停止在Entity.SaveChanges()上,所以我完全确定它会运行)
非常感谢您
编辑,我刚刚看到我的DataServiceContext的ApplyingChanges设置为false,但它不是我可以编辑的属性,与我的问题有联系吗?
I've created a small WCF Data service, I can Add/retrieve data without any problem.
I've a set on this collection "Household", with all rights:
config.SetEntitySetAccessRule("HouseHold", EntitySetRights.All);
The problem is that I just can't edit:
HouseHold houseHold = entities.HouseHold.Where(h => h.IDHouseHold == varContainingAnExistingId).FirstOrDefault();
houseHold.LastName = "LastName" + DateTime.Now;
entities.SaveChanges();
I don't have any exception, my data is just not updated in the database.
I'm missing something? I should do something more to save my changes?
(My breakpoint stops on the entities.SaveChanges(), so I'm perfectly sure that it runs)
Thank you very much
Edit, I just saw that the ApplyingChanges of my DataServiceContext is set to false, but it's not a property I can edit, is there a link with my problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试启用 DataServiceConfiguration.UseVerboseErrors?
http://msdn.microsoft.com/en -us/library/system.data.services.dataserviceconfiguration.useverboseerrors.aspx
have you tried to enable DataServiceConfiguration.UseVerboseErrors?
http://msdn.microsoft.com/en-us/library/system.data.services.dataserviceconfiguration.useverboseerrors.aspx
我最终通过探索上下文的方法找到了解决方案:
wcf 数据服务没有更改跟踪,然后您必须指定对象已更改。这个问题仅在修改时发生,因为在添加/删除时我们必须调用自动放置更改标志的特殊方法。
因此,在我的示例中,以下代码有效:
UpdateObject 是重要的更改。
I finally found the solution by exploring context's methods:
There is no change tracking with wcf data service, you then have to specify that the object has changed. This problem happens only when modifying because when adding/deleting we have to call specials methods which put changes flags automatically.
So with my example, the following code is working:
The UpdateObject is the important change.