Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 279
karaxuna Avatar asked Jul 18 '26 04:07

karaxuna


1 Answers

I found a solution:

context.ObjectStateManager
       .GetObjectStateEntries(EntityState.Added /* All states here */)
       .Select(e => e.Entity)
       .OfType<IModel>()
       .ToList();
like image 53
karaxuna Avatar answered Jul 21 '26 09:07

karaxuna