I want to pass a string in the LINQ query.
string TableName = "db.Countries";
var ActualData = (from n in TableName
where n.Record_Instance >= 0
select n).OrderBy(primaryColumn);
My aim behind this is; I want to put the query in a method and call it whenever I need it. Basically changing the TableName and passing it as a parameter on function call.
Is there a way to do this?
Update :
Workaround :
var TableName = db.Countries;
GetConditionaldata(TableName,..);
private object GetConditionaldata( DbSet<Country> TableName, ..)
{
var ConditionalData = (from n in TableName
where n.Record_Instance >= 0
select n).OrderBy(primaryColumn);
var count = ConditionalData.Count();
var countries = ConditionalData.Skip(jtStartIndex).Take(jtPageSize);
return countries;
}
But Here, I want have to again specify DbSet<Country>
as the parameter type. If I can at least find a way to get a Generic Dbset<> Which I can pass on as parameter type for my tableName, then my problem would be solved.