I am trying to build a controller that services edit requests for all my lookup tables. I have several DbSet variables on my DbContext that derive from IdNamePairBase, e.g:
public DbSet<Country> Countries { get; set; } // Country derives from IdNamePairBase
How can I pass the name of one of these to a query, to get all items in that list? E.g.
var list = db.GetNamedDbSet("Countries");
Then, for bonus points I need to get an IEnumerable<IdNamePairBase> from list.
You could use the
Set(Type type)on the DbContext if the name of the table corresponds to the type.Original Answer
If the name of the set matches the property name, you can use reflection.