如何通过实现IDATASERVICEUPDATEPROVIDER来更新Azure表存储资源?
-
29-09-2019 - |
题
我试图揭露一个可编辑的Azure表存储表。 (如果很重要:要通过ODATA客户端LIB CTP赢得电话7。)在服务器端,我有一个DataServiceContext:TableServiceContext,iDataserviceupdateProvider
我可以添加和删除对象,但是当我尝试更新资源时,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();
}
更新:答案是在setValue()中调用updateObject():
public void SetValue(object targetResource, string propertyName, object propertyValue)
{
var propInfo = targetResource.GetType().GetProperty(propertyName);
propInfo.SetValue(targetResource, propertyValue, null);
UpdateObject(targetResource);
}
解决方案
更新:答案是在setValue()中调用updateObject():
public void setValue(object targetResource,字符串属性名称,对象属性value){var propinfo = targetResource.getType()。getProperty(propertyName); propinfo.setValue(targetResource,propertyValue,null); updateObject(targetResource); }
不隶属于 StackOverflow