Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Querying an entity with Linq with name based on a string

$
0
0

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 "";
}


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>