There is an unsaved comment in progress. You will lose your changes if you continue. Are you sure you want to reopen the work item?
Problem with EndEdit in ViewModelDetailBase
I’ve created a WPF application that uses Entity Framework against the Northwind database. I’ve come across a problem when editing a single entity that inherits from ViewModelDetailBase, specifically when calling the EndEdit method.
For the benefit of other readers, in CopyValuesTo<T>(this T source, T dest) [which gets called from EndEdit], the code first gets a list of all of the entity’s properties. In this case the entity is a Product (as created from the Northwind database by EF) and it contains the Category navigation property. The code then loops round the list of the Product’s properties and effectively makes a copy. However, when it gets to the Category navigation property an exception is raised (“An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key.”).
My guess here is that this is because Category is a navigation property of the Product entity rather than a data property? If this is the case is extra filtering needed to exclude this property from the list?
Apologies that this is somewhat convoluted - I hope all this make sense!
Cheers - Graham