Breeze的_prepareSaveResult中的错误

时间:2015-01-20 23:42:50

标签: breeze

我有一个利用BeforeSaveEntities进行服务器端验证的设置。一切都按预期工作,直到我结束(在breeze.debug.js):

proto._prepareSaveResult = function (saveContext, data) {
  // if lower case then all properties are already in there 'correct' case
  // and the entityType name is already a client side name.
  if (data.entities) {
    // data: { entities: array of entities, keyMappings array of keyMappings
    //   where: keyMapping: { entityTypeName: ..., tempValue: ..., realValue ...   }
    return data;
  } else {
    // else if coming from .NET
    // HACK: need to change the 'case' of properties in the saveResult
    // but KeyMapping properties internally are still ucase. ugh...
    var keyMappings = data.KeyMappings.map(function (km) {
    var entityTypeName = MetadataStore.normalizeTypeName(km.EntityTypeName);
    return { entityTypeName: entityTypeName, tempValue: km.TempValue, realValue: km.RealValue };
  });
  return { entities: data.Entities, keyMappings: keyMappings };
}  

data参数没有KeyMappings属性,因此当Breeze尝试访问map-property时执行结束。

{"$id":"1","$type":"Breeze.ContextProvider.SaveError, Breeze.ContextProvider","Message":"Exception of type 'Breeze.ContextProvider.EntityErrorsException' was thrown.","EntityErrors":[{"$id":"2","$type":"Breeze.ContextProvider.EntityError, Breeze.ContextProvider","ErrorName":null,"EntityTypeName":null,"KeyValues":null,"PropertyName":"NameExists","ErrorMessage":"The name already exists"}]}

其他人遇到过此事吗?

更新

我已经通过NuGet不断更新所有内容,我使用的当前版本是1.5.2。 (尝试将NuGet从Stable改为Prerelease)。

以下是一些代码摘录:

    private Dictionary<Type, List<EntityInfo>> BeforeSaveEntities(Dictionary<Type, List<EntityInfo>> saveMap)
    {
        _entityErrors.Clear();
        foreach (var type in saveMap)
        {
            var entityInfoList = type.Value;
            foreach (var entityInfo in entityInfoList)
            {
                if (_actions.ContainsKey(entityInfo.Entity.GetType()))
                {
                    _actions[entityInfo.Entity.GetType()].Invoke(entityInfo);
                }
            }
        }
        if (_entityErrors.Count > 0)
        {
            throw new EntityErrorsException(_entityErrors);
        }
        return saveMap;
    }

    public SaveResult SaveChanges(Newtonsoft.Json.Linq.JObject saveBundle)
    {
        return _contextProvider.SaveChanges(saveBundle);
    }

0 个答案:

没有答案