1
這個問題的BreezeSharp - ExecuteQuery fails with NullReferenceExeptionBreezeSharp - 枚舉序列化失敗
在我的服務器端實體續集我有枚舉屬性:
[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)
當我排除模型數據存儲性能,一切工作正常。它看起來像BreezeSharp試圖解析枚舉爲int。
我嘗試將客戶端屬性定義爲字符串,但這會引發不一致的CLRPropertyDefinition元數據不匹配。我也試圖定義這樣的客戶端屬性:
公衆的DataStore數據存儲 { 得到 {VAR 的數據存儲= this.GetValue( 「數據存儲」); 返回DataStore.DEV; } set {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);
}
有誰已經知道在哪裏從這裏出發?
我確認現在支持枚舉並且問題不再存在。謝謝Jay! – markolazic88