How to have all the no deleted entities?
With Northwind, if you do this:
you will get all the categories which are in DB. It means that you won’t have context added categories and you will have deleted entities.
Now, if you do this:
context.ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityState.Modified | EntityState.Unchanged).Select(ose => ose.Entity).OfType<Category>()
you will have only the entities already loaded into the context.
To have all the entities without deleted one, you can do this:
context.Categories.AsEnumerable().Where(c => c.EntityState != EntityState.Deleted).Union(context.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Select(ose => ose.Entity).OfType<Category>())