Wcf数据服务实体的UpdateObject

时间:2012-02-29 14:55:45

标签: wcf-data-services

我有价格和PriceGroup实体,我想同时更新两个实体,如下所示:     DataContext.AddObject(“Price / PriceGroup”,oEditPrices);     DataContext.UpdateObject(oEditPrices);     DataContext.SaveChanges();

giving me error

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <code></code>
  <message xml:lang="en-US">The request URI is not valid. Since the segment 'Prices' refers to a collection, this must be the last segment in the request URI. All intermediate segments must refer to a single resource.</message>
</error>

1 个答案:

答案 0 :(得分:0)

AddObject first参数必须是实体集的名称。所以没有斜线(我知道API不会验证,不幸的是它应该验证)。这可能是它失败的原因(虽然没有HTTP跟踪我无法验证)。

如果调用AddObject,则不需要在同一个实例上调用UpdateObject,它将无效。

如果目标是添加新对象并将其与现有对象关联,则可以调用AddRelatedObject。在上面的例子中,它将类似于:

DataContext.AddRelatedObject(existingPriceObject,“PriceGroup”,newPriceGroup); DataContext.SaveChanges();

如果您需要将其作为一个操作执行(类似于事务),您可以将Batch选项传递给SaveChanges调用。