Come posso aggiornare risorsa Azure Storage Table mediante l'attuazione di IDataServiceUpdateProvider?
-
29-09-2019 - |
Domanda
sto cercando di esporre una tabella Azure Storage Table modificabile. (Se è importante:. A Win Phone 7 tramite il client OData Lib CTP) Sul lato server, ho un DataServiceContext: TableServiceContext, IDataServiceUpdateProvider
posso aggiungere e oggetti di eliminazione, ma quando provo ad aggiornare una risorsa, SaveChanges () non sembra per "raccogliere" i valori che erano stati assegnati nelle chiamate a 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: La risposta è stato quello di chiamare updateObject () durante SetValue ():
public void SetValue(object targetResource, string propertyName, object propertyValue)
{
var propInfo = targetResource.GetType().GetProperty(propertyName);
propInfo.SetValue(targetResource, propertyValue, null);
UpdateObject(targetResource);
}
Soluzione
UPDATE: La risposta è stato quello di chiamare updateObject () durante SetValue ():
SetValue public void (oggetto targetResource, string propertyName, oggetto propertyValue) { var PROPINFO = targetResource.GetType () GetProperty (propertyName).; propInfo.SetValue (targetResource, propertyValue, nullo); UpdateObject (targetResource); }