I need to get table data from table name from Linq DataContext.
Instead of this
var results = db.Authors;
I need to do something li
If you know the type, you can cast it. From http://social.msdn.microsoft.com/Forums/en-US/f5e5f3c8-ac3a-49c7-8dd2-e248c8736ffd/using-variable-table-name-in-linq-syntax?forum=linqprojectgeneral
MyDataContext db = new MyDataContext();
Assembly assembly = Assembly.GetExecutingAssembly();
Type t = assembly.GetType("Namespace." + strTableName);
if (t != null)
{
var foos = db.GetTable(t);
foreach (var f in foos)
{
PropertyInfo pi = f.GetType().GetProperty("Foo");
int value = (int)pi.GetValue(f, null);
Console.WriteLine(value);
}
}