Breeze / breeze.server.net

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

Fixed bug with null and not-null values in originalValuesMap #47

Closed orange-bird closed 6 years ago

orange-bird commented 7 years ago

When applying values from originalValuesMap not-null original values are lost if they were processed before null. Because of EF bug we need to set all DBNull values first and only after that assign remaining not-null values.

steveschmitt commented 7 years ago

Thanks! I haven't observed this problem myself. Do you have a test case that demonstrates the problem? Or can you describe the scenario? Thanks again.

orange-bird commented 7 years ago

I have no ready test but scenario.

Assume we're changing entity with 2 modified properties: property1 and property2. Original value for property1 doesn't equal to null, but original value for property2 is null. When Context Provider handles modified properties one by one (in UpdateOriginalValues method): property1 at first, property2 at second. This lines will be executed: var temp = entry.CurrentValues[ordinal]; entry.CurrentValues.SetDBNull(ordinal); entry.ApplyOriginalValues(entry.Entity); entry.CurrentValues.SetValue(ordinal, temp); When property2 is handled line with ApplyOriginalValues() method overwrites all previously processed original values including value for property1. So original value for property1 is reset.

This scenario does not affect save process nor makes it incorrect. But if we need to make some decisions after save that are based on changed properties then it doesn't work as we want. Currently we're using workaround by ordering original values map with null values first.

steveschmitt commented 7 years ago

Great, thanks for the explanation. We need to be careful with this, because the original values are also used to hook up the entity relationships via the foreign key properties.

steveschmitt commented 6 years ago

The underlying EF bug appears to have been fixed in recent versions of EF, so the entry.ApplyOriginalValues approach is no longer necessary, and the OriginalValues can be set property without having to reorder them. The fix is in breeze.server.net 1.6.6.

Thanks for all your work on this.