问题
Not sure if it is a bug, but: When you have extended type with observable it is also serialized in saveChanges. This makes EFContextProvider to fail on deleting entities.
Example of json sent:
{"entities": [{
"Id":1015,
"Key":"3",
"Value":"2",
"undefined":"",
"entityAspect":{
"entityTypeName":"Setting:#Settings_Beeze.Models",
"entityState":"Deleted",
"originalValuesMap":{"isBeingEdited":false},
"autoGeneratedKey":{
"propertyName":"Id",
"autoGeneratedKeyType":"Identity"}}}],
"saveOptions":{
"allowConcurrentSaves":false}}
isBeingEdited - is client-side observable, and shouldn't be sent to server (I think so). It also generates field undefined (which is not part of extended object, it comes from nowhere).
So server-side code fails in EFContextProvider with NullReferenceException, here is stack trace:
at Breeze.WebApi.EFContextProvider`1.SetPropertyValue(Object entity, String propertyName, Object value)
at Breeze.WebApi.EFContextProvider`1.<>c__DisplayClassd.<RestoreOriginal>b__c(KeyValuePair`2 kvp)
at System.Collections.Generic.List`1.ForEach(Action`1 action)
at Breeze.WebApi.EFContextProvider`1.RestoreOriginal(EntityInfo entityInfo)
at Breeze.WebApi.EFContextProvider`1.<ProcessAllDeleted>b__6(EFEntityInfo entityInfo)
at System.Collections.Generic.List`1.ForEach(Action`1 action)
at Breeze.WebApi.EFContextProvider`1.ProcessAllDeleted(List`1 deletedEntities)
at Breeze.WebApi.EFContextProvider`1.SaveChangesCore(Dictionary`2 saveMap)
at Breeze.WebApi.ContextProvider.SaveChanges(JObject saveBundle)
at Settings_Beeze.Controllers.DataController.SaveChanges(JObject saveBundle) in s:\Projects\Else\Settings Beeze\Settings Beeze\Controllers\DataController.cs:line 35
at lambda_method(Closure , Object , Object[] )
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters)
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.<>c__DisplayClass5.<ExecuteAsync>b__4()
at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)
As fix idea: unwrapOriginalValues should check whether property is unmapped and continue to the next one wihout writing it to the answer.
- moved issue from GitHub to SO
回答1:
Sounds like a bug to me. We'll jump on it.
来源:https://stackoverflow.com/questions/15508233/1-2-1-unmapped-properties-shouldnt-be-serialized