Version Info:
I am using C# 4.5, Entity Framework 6.0, and MEF.
Code and Unit Test
I created a Test Project to expl
As I wasn't able to cast a generic DbSet to a typed DbSet I used instead a typed IQueryable which can do the same things I needed from the DbSet.
Here is a extension that can get you that:
public static IQueryable GetIQueryableByTableName(this DbContext context, string tableName)
{
var type = Assembly.GetExecutingAssembly().GetTypes().FirstOrDefault(t => t.Name == tableName);
if (type == null)
{
throw new Exception("GetIQueryableByTableName received an invalid table name.");
}
return context.GetType().GetMethod("Set", new Type[0]).MakeGenericMethod(type).Invoke(context, new object[0]) as IQueryable;
}