This project has moved and is read-only. For the latest updates, please go here.

How can I access an entity that has been marked as deleted?

Feb 9, 2015 at 7:02 PM
On the Client side, when I attempt to access an entity that has been marked as deleted, it does not appear in the entity set; though it is reflected in the TotalCount, and will in fact get deleted when calling SaveChanges().

I can’t access an entity that is marked as deleted.
var entity = DataContext.EntitySet.Where(x => x.ChangeTracker.State == ObjectState.Deleted).FirstOrDefault();
The deleted entity does not show up in my foreach loop.
foreach (var entity in DataContext.EntitySet.Where(x => x.ChangeTracker.State == ObjectState.Deleted))
How do I access the entity marked as deleted when I’m in the Client, before saving changes? Any suggestions? I am using version N-Tier Entity Framework 1.5

Thank you!
Feb 10, 2015 at 9:24 AM
Entities marked as deleted are hidden and don't get returned when enumerating the entity set.
To get all entities (i.e. including deleted) you can use the following method:
foreach (var entity in DataContext.EntitySet.GetAllEntities().Where(x => x.ChangeTracker.State == ObjectState.Deleted))
Marked as answer by LorenNicoleBetz on 2/12/2015 at 5:08 AM
Feb 12, 2015 at 1:08 PM
This works great! Thank you.