Как я могу обновить ресурс хранения таблицы Azure, внедрив IdataServiceUpdateProvider?
-
29-09-2019 - |
Вопрос
Я пытаюсь разоблачить редактируемый таблицу хранения таблиц Azure. (Если это имеет значение: чтобы выиграть телефон 7 через клиент ODATA Lib Ctp.) На стороне сервера у меня есть 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();
}
Обновление: Ответ должен был вызовать UpdateObject () во время setValue ():
public void SetValue(object targetResource, string propertyName, object propertyValue)
{
var propInfo = targetResource.GetType().GetProperty(propertyName);
propInfo.SetValue(targetResource, propertyValue, null);
UpdateObject(targetResource);
}
Решение
Обновление: Ответ должен был вызовать UpdateObject () во время setValue ():
public void setValue (объект Targetresource, String PropertyName, объект PropertyValue) {var propInfo = targetresource.getType (). getProperty (PropertyName); propinfo.setValue (TargetResource, PropertyValue, NULL); UpdateObject (TargetResource); }