Pergunta

I am trying to expose an editable Azure Table Storage table. (If it matters: to Win Phone 7 via the OData Client Lib CTP.) On the server side, I have a DataServiceContext : TableServiceContext, IDataServiceUpdateProvider

I can add and delete objects, but when I try to update a resource, SaveChanges() does not appear to "pick up" the values that had been assigned in the calls to 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: Answer was to call UpdateObject() during SetValue():

public void SetValue(object targetResource, string propertyName, object propertyValue)
    {
        var propInfo = targetResource.GetType().GetProperty(propertyName);
        propInfo.SetValue(targetResource, propertyValue, null);
        UpdateObject(targetResource);
    }
Foi útil?

Solução

UPDATE: Answer was to call UpdateObject() during SetValue():

public void SetValue(object targetResource, string propertyName, object propertyValue) { var propInfo = targetResource.GetType().GetProperty(propertyName); propInfo.SetValue(targetResource, propertyValue, null); UpdateObject(targetResource); }

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top