0

我正在尝试公开一个可编辑的 Azure 表存储表。(如果重要:通过 OData Client Lib CTP 赢得 Phone 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);
    }
4

1 回答 1

0

更新:答案是在 SetValue() 期间调用 UpdateObject():

public void SetValue(object targetResource, string propertyName, object propertyValue) { var propInfo = targetResource.GetType().GetProperty(propertyName); propInfo.SetValue(targetResource, propertyValue, null); 更新对象(目标资源);}

于 2010-10-12T02:09:18.873 回答