karaxuna
karaxuna

Reputation: 26940

Get all entities that implement interface

I have several entities that implement IModel interface. I want to get records from all tables whose entities implement this interface. Is it possible?

Upvotes: 3

Views: 195

Answers (1)

karaxuna
karaxuna

Reputation: 26940

I found a solution:

context.ObjectStateManager
       .GetObjectStateEntries(EntityState.Added /* All states here */)
       .Select(e => e.Entity)
       .OfType<IModel>()
       .ToList();

Upvotes: 2

Related Questions