I have a method that returns records from a dynamically presented table:
public static List<T> Get<T>() where T : class
{
using NanoWikiDBContext context = new NanoWikiDBContext();
return context.Set<T>().AsQueryable().ToList();
}
And now I need to get records, when there is no type T, by the table name. How to do it?
You can't just pass GetType (), it doesn't work. What is a way to get data through a dynamic object without using generic T directly?
public static List<T> GetByName<T>(string table) where T : class
{
using NanoWikiDBContext context = new NanoWikiDBContext();
var model = Activator.CreateInstance(Type.GetType($"{StringsManager.GetProjectName()}.Models.Database.{table}")).GetType();
return context.Set<model.GetType()>().AsQueryable().ToList();
}