none
Entity Framework get referenced entrys from deleted entry RRS feed

  • Question

  • I' am using Entity Framework 4.2 and I want to display the changes that are made to the object context in a DataGrid. Displaying modified and added entrys are no problem, but on the deleted entries that I want to display the references are also removed. Is it possible to get the original object including the referenced entries using the ChangeTracker even if the entry is deleted?
    Monday, December 12, 2011 9:57 PM

Answers

  • Hi TheNetStriker,

    Here is the test code, hope it helps:

      var vacation = context.Vacations.FirstOrDefault();
                    context.Vacations.Remove(vacation);
                  var entities=  context.ChangeTracker.Entries<Vacation>();
                  foreach (var item in entities)
                  {
                      if(item.State== System.Data.EntityState.Deleted)
                      {
                          Console.WriteLine(item.OriginalValues.GetValue<int>("Days"));
                      }
                  }   
    

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, December 15, 2011 12:42 PM
    Moderator