I have written a code like this and it works fine .
List<lbmaster> l1 = new List<lbmaster>();
int str123 = 2;
string nam;
using (MockContext Db = new MockContext())
{
l1=Db.lb_master.Where(_ => _.id==str123)
.ToList();
nam= l1[0].tablename;
}
using (var Db1 = new MockContext())
{
switch (nam)
{
case "Users": return Db1.Users.ToList();
break;
case "lb_master": return Db1.lb_master.ToList();
break;
}
}
But i want to write a code in such a way that i don't have to use switch case, instead I just use the "nam" variable which contains the table name as string and through that i want to access the table
eg : Db1.nam.ToList();
Is there any way to achieve this, coz i've tried Get table by name with Entity Framework and others but am not able to achieve this.
Context name : MockContext table names : "Users" and "lb_master" lb_master contains the list of other tables name so i'm fetching the tabel name from lb_master and from that string wanna access the table
Is it possible to achieve this?
thank You!!