使用Breeze删除具有修改的枚举属性的实体

时间:2013-12-16 23:06:50

标签: breeze

当我尝试删除同时具有修改的枚举属性的实体时,我遇到了问题。我得到的错误是从'System.String'到'BV.Entities.CarType'的无效投射。一个简单的例子如下:

public class Car {
  public int Id { get; set; }
  public CarType Type { get; set; } // CarType is an enum
}

var car = // load a car entity
car.Type('Sedan');
car.entityAspect.setDeleted();
manager.saveChanges();

例如,当用户开始编辑记录,然后决定只删除它时,就会发生这种情况。

我还使用了DocCode示例来测试它。我编辑了saveTodoTests.js并使用了“可以在一个批处理中保存添加,更新和删除”测试,类似于此处Exception in client breeze.js when using enum property on model的建议。如果我改变了deleteTodo项的枚举类型,则会抛出错误,如果我删除了setDeleted(),它将正确保存它。

System.InvalidCastException was unhandled by user code
  HResult=-2147467262
  Message=Invalid cast from 'System.String' to 'BV.Entities.CarType'.
  Source=mscorlib
  StackTrace:
       at System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider provider)
       at System.String.System.IConvertible.ToType(Type type, IFormatProvider provider)
       at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
       at Breeze.ContextProvider.EF6.EFContextProvider`1.ConvertValue(Object val, Type toType)
       at Breeze.ContextProvider.EF6.EFContextProvider`1.SetPropertyValue(Object entity, String propertyName, Object value)
       at Breeze.ContextProvider.EF6.EFContextProvider`1.<>c__DisplayClass10.<RestoreOriginal>b__f(KeyValuePair`2 kvp)
       at System.Collections.Generic.List`1.ForEach(Action`1 action)
       at Breeze.ContextProvider.EF6.EFContextProvider`1.RestoreOriginal(EntityInfo entityInfo)
       at Breeze.ContextProvider.EF6.EFContextProvider`1.<ProcessAllDeleted>b__9(EFEntityInfo entityInfo)
       at System.Collections.Generic.List`1.ForEach(Action`1 action)
       at Breeze.ContextProvider.EF6.EFContextProvider`1.ProcessAllDeleted(List`1 deletedEntities)
       at Breeze.ContextProvider.EF6.EFContextProvider`1.SaveChangesCore(SaveWorkState saveWorkState)
       at Breeze.ContextProvider.ContextProvider.OpenAndSave(SaveWorkState saveWorkState)
       at Breeze.ContextProvider.ContextProvider.SaveChanges(JObject saveBundle, TransactionSettings transactionSettings)
       at BV.Web.Controllers.DefaultController.SaveChanges(JObject saveBundle) in c:\Work\Code\BV\BV.Web\Controllers\DefaultController.cs:line 59

1 个答案:

答案 0 :(得分:0)

好的,这是一个错误,并在GitHub上当前breeze.server.net和breeze.js repos的组合中修复。它也将在下周某个时候作为下一个版本(1.4.14)的一部分发布。