通过 LINQ 编辑 WCF 数据服务的数据

发布于 2024-11-29 21:12:14 字数 621 浏览 0 评论 0原文

我创建了一个小型 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怀里藏娇 2024-12-06 21:12:14

我最终通过探索上下文的方法找到了解决方案:

wcf 数据服务没有更改跟踪,然后您必须指定对象已更改。这个问题仅在修改时发生,因为在添加/删除时我们必须调用自动放置更改标志的特殊方法。

因此,在我的示例中,以下代码有效:

HouseHold houseHold = entities.HouseHold.Where(h => h.IDHouseHold == varContainingAnExistingId).FirstOrDefault();
houseHold.LastName = "LastName" + DateTime.Now;
entities.UpdateObject(houseHold);
entities.SaveChanges();

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:

HouseHold houseHold = entities.HouseHold.Where(h => h.IDHouseHold == varContainingAnExistingId).FirstOrDefault();
houseHold.LastName = "LastName" + DateTime.Now;
entities.UpdateObject(houseHold);
entities.SaveChanges();

The UpdateObject is the important change.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文