C# 按表名获取列实体框架反射

C# 按表名获取列实体框架反射,c#,entity-framework,reflection,dataset,C#,Entity Framework,Reflection,Dataset,我需要从我只知道名称的表中获取列名和值。 我尝试了很多东西,但没有成功 我用这个来拿我的桌子: var table = oSession.ctx.GetType() .GetProperty("country") .GetValue(oSession.ctx, null); 我无法检索到我的专栏的信息,对此我很抱歉。。 也许我已经试过了: List<string> columnsNames

我需要从我只知道名称的表中获取列名和值。 我尝试了很多东西,但没有成功

我用这个来拿我的桌子:

var table = oSession.ctx.GetType()
                       .GetProperty("country")
                       .GetValue(oSession.ctx, null);
我无法检索到我的专栏的信息,对此我很抱歉。。 也许我已经试过了:

List<string> columnsNames = table.GetType().GetFields().Select(field => field.Name).ToList();
List columnsames=table.GetType().GetFields().Select(field=>field.Name).ToList();

谢谢你的帮助

您可能可以尝试使用GetProperties() table.GetType().GetProperties().Where(p=>!(p.GetMethod.IsVirtual | | | p.GetIndexParameters().Length>0)).ToList()

使用
((IQueryable)table.ElementType.GetProperties()
作为起点。你也可以从中得到一些想法