我想从具有特定 accountID 的实体模型(我使用的是 EF 版本 5)中获取记录列表。我得到了 tableName 字符串(这必须是动态的)和 accountID。我正在尝试以下 2 种方法,但它们都不起作用(在 IQueryable 对象“表”上出现错误:
PropertyInfo info = _db.GetType().GetProperty(tableName);
IQueryable table = info.GetValue(_db, null) as IQueryable;
var query = table.Where(t => t.AccountID == accID)
.Select(t => t);
List <object> recList = ( from records in table
where records.AccountID == accID
select records).ToList<object>();