Get table-data from table-name in LINQ DataContext

前端 未结 4 1940
庸人自扰
庸人自扰 2020-11-28 13:46

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

4条回答
  •  借酒劲吻你
    2020-11-28 14:25

    Given DataContext context and string tableName, you can just say:

    var table = (ITable)context.GetType()
                               .GetProperty(tableName)
                               .GetValue(context, null);
    

提交回复
热议问题