您当然可以使用某些LINQ-To-Xml直接针对“ .edmx”文件或已编译程序集中的嵌入式模型资源来执行此操作。
以下查询获取字段(而非列)名称。如果您需要这些列,则只需更改查询即可。
var edmxNS = XNamespace.Get(@"http://schemas.microsoft.com/ado/2007/06/edmx");
var schemaNS = XNamespace.Get(@"http://schemas.microsoft.com/ado/2006/04/edm");
var xd = XDocument.Load(@"{path}\Model.edmx");
var fields =
from e in xd
.Elements(edmxNS + "Edmx")
.Elements(edmxNS + "Runtime")
.Elements(edmxNS + "ConceptualModels")
.Elements(schemaNS + "Schema")
.Elements(schemaNS + "EntityType")
from p in e
.Elements(schemaNS + "Property")
select new
{
Entity = e.Attribute("Name").Value,
Member = p.Attribute("Name").Value,
Type = p.Attribute("Type").Value,
Nullable = bool.Parse(p.Attribute("Nullable").Value),
};