I'm trying to retrieving a DbContext DbSet property by its name but I don't know how to handle the generic parameter.
DataSource.Load(IQuerable source) method comes from an external dll and I cannot modify it.
Knowing the property name of my DbSet prop (from an entity framework dbcontext class) I want to use that property value as parameter for DataSource.Load
public class DataManager
{
private MyDbContext _dbContext;
public DataManager(MyDbContext dbContext)
{
_dbContext = dbContext;
}
public object Load(string propName)
{
var source = _dbContext.GetType().GetProperty(entityName).GetValue(_dbContext, null);
return DataSourceLoader.Load(source);
}
//DataSourceLoader.Load signature:
//DataSourceLoader.Load<T>(System.Linq.IQueryable<T>)
Update
To be more clear: DataSourceLoader.Load loads data from an entity set; I don't care of the return type because it will be serialized and sent to a client plugin.
A client plugin requests the data by an ajax call using the entitySet name as parameter. I don't want to have a different method (or a long switch statement) for each entity set I have and statically invoke the DataSource.Load method.
I would like to resolve the entity set to query at runtime