DataServiceContext 中的 AddLink 和 SetLink
我是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您能告诉我您到底遇到了什么错误吗?也许小提琴手跟踪会有所帮助。
另外,如果您想要该服务,可以在服务器中打开调试模式,以便获得详细的异常消息 - 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