我有一个使用OData客户端的UWP应用程序。我的Customer
有Order
个集合。当我通过订单数据服务为该客户添加新订单时,我需要为客户对象重新加载此属性。我在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);