1

这个问题是BreezeSharp 的续集 - ExecuteQuery failed with NullReferenceExeption

在我的服务器端实体中,我有枚举属性:

[Required]
public DataStore DataStore { get; set; }

客户端实体中的此属性定义如下:

    public DataStore DataStore
    {
        get { return GetValue<DataStore>(); }
        set { SetValue(value); 
    }

当控制器方法向客户端返回数据时,出现序列化错误:“输入字符串格式不正确。

这是堆栈跟踪:

at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at System.String.System.IConvertible.ToInt32(IFormatProvider provider)
   at System.Convert.ToInt32(Object value, IFormatProvider provider)
   at Newtonsoft.Json.Linq.JToken.op_Explicit(JToken value)
   at Newtonsoft.Json.Linq.JToken.ToObject(Type objectType)
   at Breeze.Sharp.JsonEntityConverter.<>c__DisplayClassa.<ParseObject>b__6(KeyValuePair`2 kvp) in c:\GitHub\breeze.sharp\Breeze.Sharp\JsonEntityConverter.cs:line 195
   at Breeze.Sharp.Core.EnumerableFns.ForEach[T](IEnumerable`1 items, Action`1 action) in c:\GitHub\breeze.sharp\Breeze.Sharp\Core\EnumerableFns.cs:line 35
   at Breeze.Sharp.JsonEntityConverter.ParseObject(NodeContext nodeContext, EntityAspect targetAspect) in c:\GitHub\breeze.sharp\Breeze.Sharp\JsonEntityConverter.cs:line 180
   at Breeze.Sharp.JsonEntityConverter.PopulateEntity(NodeContext nodeContext, IEntity entity) in c:\GitHub\breeze.sharp\Breeze.Sharp\JsonEntityConverter.cs:line 152
   at Breeze.Sharp.JsonEntityConverter.CreateAndPopulate(NodeContext nodeContext) in c:\GitHub\breeze.sharp\Breeze.Sharp\JsonEntityConverter.cs:line 143
   at Breeze.Sharp.JsonEntityConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer) in c:\GitHub\breeze.sharp\Breeze.Sharp\JsonEntityConverter.cs:line 82
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)

当我从模型中排除 DataStore 属性时,一切正常。看起来 BreezeSharp 正在尝试将枚举解析为 int。

我尝试将客户端属性定义为字符串,但这会引发InconsistentCLRPropertyDefinition元数据不匹配。我还尝试像这样定义客户端属性:

公共数据存储数据存储 { 获取 { var dataStore = this.GetValue("DataStore"); 返回数据存储.DEV;} 设置 { this.SetValue(value); 但问题发生在 get 被击中之前。

我查看了 JsonEntityConverter.cs,看起来此时枚举没有单独处理:

private void ParseObject(NodeContext nodeContext, EntityAspect targetAspect) {
      // backingStore will be null if not allowed to overwrite the entity.
      var backingStore = (targetAspect == null) ? null : targetAspect.BackingStore;
      var dict = (IDictionary<String, JToken>) nodeContext.Node;
      var structuralType = nodeContext.StructuralType;
      // needs to be the current namingConvention
      var nc = _mappingContext.EntityManager.MetadataStore.NamingConvention;
      dict.ForEach(kvp => {
        var key = nc.ServerPropertyNameToClient(kvp.Key, structuralType);
        var prop = structuralType.GetProperty(key);
        if (prop != null) {         
          if (prop.IsDataProperty) {
            if (backingStore != null) {
              var dp = (DataProperty)prop;
              if (dp.IsComplexProperty) {
                var newCo = (IComplexObject) kvp.Value.ToObject(dp.ClrType);
                var co = (IComplexObject)backingStore[key];
                var coBacking = co.ComplexAspect.BackingStore;
                newCo.ComplexAspect.BackingStore.ForEach(kvp2 => {
                  coBacking[kvp2.Key] = kvp2.Value;
                });
              } else {
                backingStore[key] = kvp.Value.ToObject(dp.ClrType);
              }

有谁知道从这里开始?

4

1 回答 1

0

这已在 Breeze 0.5.5 中得到修复,现在可用。

于 2014-06-04T01:39:06.070 回答