I have a MVC project with Entity Framework. I need to be able to build a Linq query based on the name of the enitity which must be dynamic and can therefore change.
The name of the entity is retrieved from a database and is a string.
So I've made a method that is able to create a type from a string passed to the method. In theory, I should be able to use the type in a Linq query. But unfortunately, that doesn't work.
Can anybody help me? This is the code so far:
private string GetOptionsList(string LookupTable)
{
Type type = Type.GetType("Prg.Models." + LookupTable);
var query = db.Set(type);
//// Filter against "query" variable below...
//var result = query.Where(...);
var collection = (from q in query)
return "";
}