DataServiceContext 中的 AddLink 和 SetLink

发布于 2024-10-12 02:36:05 字数 741 浏览 6 评论 0原文

我是 ADO.NET 数据服务的新手。我只是想了解如何使用它。

我想设置两个现有对象 city 和comingCity 之间的链接:

IncomingCity 和 City 具有多对一关系: 城市有房产 Collection IncomingCity IncomingCity 仅有一个相关的 City -- 属性是 City City

我所做的操作:

var entities = new referenceEntities(new Uri(url));

DataServiceQuery<IncomingCity> query = entities.IncomingCity.Expand("City");

var otherCities = query.Where(ic => ic.City == null);

var first = otherCities.FirstOrDefault();

entities.AddLink(originalCity, "IncomingCity", first);
entities.SetLink(first, "City", originalCity);

first.UpdatedAt = DateTime.Now;

entities.UpdateObject(first);

entities.SaveChanges();

在 SaveChanges 方法期间发生这样的异常:

处理此请求时发生错误。

我不明白怎么了。有人知道吗?

I'm newby at ADO.NET Data Services. I'm just trying to understand how to work with it.

I'd like to set the link between two existing objects city and incomingCity:

IncomingCity and City has many-to-one relationship:
City has property Collection IncomingCity
IncomingCity has the only one related City -- the property is City City

The operations i do:

var entities = new referenceEntities(new Uri(url));

DataServiceQuery<IncomingCity> query = entities.IncomingCity.Expand("City");

var otherCities = query.Where(ic => ic.City == null);

var first = otherCities.FirstOrDefault();

entities.AddLink(originalCity, "IncomingCity", first);
entities.SetLink(first, "City", originalCity);

first.UpdatedAt = DateTime.Now;

entities.UpdateObject(first);

entities.SaveChanges();

Such an exception occurs during SaveChanges method:

An error occurred while processing this request.

I cound not understand what's the matter. Does anybody know?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

怀里藏娇 2024-10-19 02:36:05

您能告诉我您到底遇到了什么错误吗?也许小提琴手跟踪会有所帮助。

另外,如果您想要该服务,可以在服务器中打开调试模式,以便获得详细的异常消息 - http://blogs.msdn.com/b/phaniraj/archive/2008/06/18/debugging-ado-net-数据服务.aspx

希望这有帮助。

谢谢
普拉蒂克

Can you please tell what error you are getting exactly? Maybe a fiddler trace will help.

Also, if you want the service, can you turn the debugging mode on in the server so that you get a detailed exception message - http://blogs.msdn.com/b/phaniraj/archive/2008/06/18/debugging-ado-net-data-services.aspx.

Hope this helps.

Thanks
Pratik

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