如何将OData上下文标记为脏?

时间:2016-08-15 14:12:35

标签: c# odata uwp

我有一个使用OData客户端的UWP应用程序。我的CustomerOrder个集合。当我通过订单数据服务为该客户添加新订单时,我需要为客户对象重新加载此属性。我在BeginLoadProperty属性的该对象上发出Orders,但没有任何反应。我怀疑这是因为OData认为对象没有改变。我想将客户对象标记为脏,因此OData将再次获取所有属性,或者只是强制Orders属性重新加载。

public class Customer
{
    public int Id { get; set; }
    public ICollection<Phone> Phones { get; set; }
}

public class Phone
{
    public int Id { get; set; }
    [ForeignKey("Customer")]
    public int? CustomerId { get; set; }
    public virtual Customer Customer { get; set; }
}

var customerQuery = (DataServiceQuery<Customer>)Container.Customers.Where(c => c.Id == id);
var result = await customerQuery.ExecuteAsync();
var customer = result.ToList().customers.First();
Container.BeginLoadProperty(customer, "Phones", callback, object);

var newPhone = new Phone() { CustomerId = customer.Id };
Container.AddToPhones(newPhone);

var customerQuery = (DataServiceQuery<Customer>)Container.Customers.Where(c => c.Id == id);
var result = await customerQuery.ExecuteAsync();
var customer = result.ToList().customers.First();
Container.BeginLoadProperty(customer, "Phones", callback, object);

0 个答案:

没有答案