SaveChanges 不会在 OData 上使用 LINQ 实体执行任何操作



在某些情况下,我可以使用UpdateObject:欺骗它检测更改

public UpdateOrderDescription(int userId)
{
    var entities = new DatabaseEntities(new Uri("http://SomeServer/OrderService.svc")) { UsePostTunneling = true};
    var order = (from o in entities.Orders where o.UserId == userId select o).Single();
    order.Description = "Hello";
    entities.UpdateObject(order);
    entities.SaveChanges();
}

但是,当使用导航属性使用多对多关系时,这是不起作用的,因为我不能对导航属性执行UpdateObject。

看看这篇文章:http://msdn.microsoft.com/en-us/library/dd756361.aspx

简而言之,WCF DS的客户端库需要通知您要进行的更改。默认情况下,这是使用上下文上的UpdateObject、SetLink、AddLink和类似方法完成的。

最新更新