Breeze / breeze.server.net

Breeze support for .NET servers
MIT License
76 stars 62 forks source link

DateTimeOffsetConverter cannot convert from System.DateTime #32

Closed rrajewski closed 8 years ago

rrajewski commented 9 years ago
Message=DateTimeOffsetConverter cannot convert from System.DateTime.
  Source=System
  StackTrace:
       at System.ComponentModel.TypeConverter.GetConvertFromException(Object value)
       at System.ComponentModel.TypeConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
       at System.ComponentModel.DateTimeOffsetConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)
       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.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 WaterTrack.WebApi.Breeze.Controllers.BreezeController.SaveChanges(JObject saveBundle) in ...

This error occurs when trying to save changes to an entity that has a DateTimeOffset property and the entityInfo.OriginalValuesMap contains a value for that column. It seems that the when the OriginalValuesMap is parsed into a KVP, a DateTime instead of DateTimeOffset type is used for the value of the column.

Has anyone else run into this?

steveschmitt commented 8 years ago

You could try changing the JsonSerializerSettings.DateParseHandling to DateParseHandling.DateTimeOffset (instead of DateTime), which would cause all dates to be parsed into DateTimeOffsets. That would probably break a bunch of other stuff, though.

steveschmitt commented 8 years ago

I put in a fix for this particular case; no DateParseHandling change required.

rrajewski commented 8 years ago

Awesome. Thanks!