我想从实体模型(我使用EF版本5)获取具有特定accountID的记录列表.我正在提供tableName字符串(这必须是动态的)和accountID.我正在尝试以下两种方法,但它们都没有工作(给我IQueryable对象'table'的错误:
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>();
Run Code Online (Sandbox Code Playgroud)