我需要从一个只知道名称的表中获取列名和值。 我尝试了很多但没有成功。
我用它来获取我的表:
var table = oSession.ctx.GetType()
.GetProperty("country")
.GetValue(oSession.ctx, null);
我锁定了我无法检索列的信息。 也许我已经尝试过了:
List<string> columnsNames = table.GetType().GetFields().Select(field => field.Name).ToList();
谢谢你的帮助..
答案 0 :(得分:2)
使用((IQueryable)table).ElementType.GetProperties()
作为起点。您也可以从Dynamic LINQ query to get Field value from Database
答案 1 :(得分:0)
您可以尝试使用GetProperties() table.GetType()。GetProperties()。Where(p =&gt;!(p.GetMethod.IsVirtual || p.GetIndexParameters()。Length&gt; 0))。ToList()