我想公開一個可編輯的Azure表存儲表。 (如果重要的話:通過OData Client Lib CTP贏得Phone 7)。在服務器端,我有一個DataServiceContext:TableServiceContext,IDataServiceUpdateProvider如何通過實現IDataServiceUpdateProvider更新Azure表存儲資源?
我可以添加和刪除對象,但是當我嘗試更新資源時, SaveChanges()似乎不能「拾取」在對SetProperty的調用中分配的值。
//Works fine
public object GetResource(IQueryable query, string fullTypeName)
{
var resource = query.Cast<MyDataModel>().SingleOrDefault();
if (fullTypeName != null && resource.GetType().FullName != fullTypeName)
{
throw new ApplicationException("Unexpected type for this resource");
}
return resource;
}
//Seems to work fine: gets called for each property.
public void SetValue(object targetResource, string propertyName, object propertyValue)
{
var propInfo = targetResource.GetType().GetProperty(propertyName);
propInfo.SetValue(targetResource, propertyValue, null);
}
//This gets called, but resource is not updated
void IUpdatable.SaveChanges()
{
//Forwarding from IUpdatable.SaveChanges() to DataServiceContext.SaveChanges()
base.SaveChanges();
}
UPDATE:答案是的SetValue()中調用UpdateObject():
public void SetValue(object targetResource, string propertyName, object propertyValue)
{
var propInfo = targetResource.GetType().GetProperty(propertyName);
propInfo.SetValue(targetResource, propertyValue, null);
UpdateObject(targetResource);
}