entity-frameworkentity-framework-4ef4-code-only

Obtaining List of Entities in DataContext


What would be the best way to obtain the list of entities loaded in a given EF 4.1 DbContext? I have been unsuccessful in attemps to locate a collection of DbEntityEntry.Entity objects loaded for a given context. It seems like it should be possible using a pattern similar to how DbContext.ChangeTracker.Entries() operates.


Solution

  • This will give you all entities in the context:

    dbContext.ChangeTracker.Entries().Select(e => e.Entity)
    

    but you will get them types as general Object.