locked
Deleting entity through dynamic data. Entity's properties all "null" except EntityKey. Why? RRS feed

  • Question

  • User75561059 posted

    Hi!

    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?

     

     

    Tuesday, April 3, 2012 10:22 AM

Answers

  • User75561059 posted

    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 Deleting event.

    "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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 4, 2012 3:14 AM

All replies

  • User75561059 posted

    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 Deleting event.

    "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.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 4, 2012 3:14 AM
  • User-330204900 posted

    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 :)

    Wednesday, April 4, 2012 9:23 AM