我的代码
var bvcD = _db.BVCData.GetBVCDataByMetric(metric);
// this one is simple "Select * from table"
从DB获取记录器列表。
我可以使用foreach循环遍历数据
foreach (var item in bvcD)
{
// How can I check if "item" has column/key "report" ?
}
答案 0 :(得分:0)
foreach (var item in bvcD)
{
Type t = item.GetType();
var props = t.GetProperties();
foreach (var p in props)
{
string columnName = p.ToString();
// Column name with type prepended
// I get column name by doing columnName.Replace("Double ", "");
// "Double" is the column dataType here
}
}
这对于检索列名来说似乎是一种丑陋的方式。 如果您有任何其他方法可以告诉我。