Last post Apr 04, 2012 09:23 AM by sjnaughton
Apr 03, 2012 10:22 AM|nobba75|LINK
I'm using dynamic data on top of Entity Framework 4.3, code first. I have some pre-save logic going on in the Saving_Changes event of the ObjectContext. For inserts everything is fine but when deleting an object from e.g. DD list view, the entity (which
is full of values when displayed in the list view) is "nulled out" when trying to perfom the pre-save logic, except from the EntityKey that still has it's value set.
I then tried to handle the GridDataSource_Deleting event but to my surprise the entity is already "blank" there as well.
Does anyone have a clue to what causes the problem?
Apr 04, 2012 03:14 AM|nobba75|LINK
Ok, will be answering this one myself.
Seems to be that the EntityDataSource used in the dynamic data page has been optimized according to this information about the
"The Deleting event is raised before the
SaveChanges method is called on the
ObjectContext to delete an object. The
Entity property of the
EntityDataSourceChangingEventArgs object is used to access the object to be deleted. The properties of this object may not be fully set. Only the properties required to identify the object must be set."
One workaround is to mark the properties you do need from the code first class with the annotation [ConcurrencyCheck]. Might of course have other implications but at least that is one way to go.
Apr 04, 2012 09:23 AM|sjnaughton|LINK
You are correct it's just the way EF deals with deletes is you create an EF SavingChanges handler and process deleted items they are all the same only a PK :)