我想从Entity Framework中读取EDMX文件中的实体集。XPath不能正常工作
的EDMX文件(XML格式),具有以下布局:
<edmx:Edmx Version="3.0" xmlns:edmx="http://schemas.microsoft.com/ado/2009/11/edmx">
<edmx:Runtime>
<edmx:ConceptualModels>
<Schema Namespace="Model" Alias="Self" p1:UseStrongSpatialTypes="false" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns:p1="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
<EntityContainer Name="EntityModel" p1:LazyLoadingEnabled="true">
<EntitySet Name="TableName" EntityType="Model.TableName" />
我使用以下XPath获取和EntityContainer中的所有EntitySet的节点:
/edmx:Edmx/edmx:Runtime/edmx:ConceptualModels/Schema/EntityContainer/EntitySet
但我没有得到任何结果使用此C#代码:
XmlDocument xdoc = new XmlDocument("pathtoedmx");
var ns = new XmlNamespaceManager(xdoc.NameTable);
ns.AddNamespace("edmx", "http://schemas.microsoft.com/ado/2009/11/edmx");
ns.AddNamespace("annotation", "http://schemas.microsoft.com/ado/2009/02/edm/annotation");
ns.AddNamespace("p1", "http://schemas.microsoft.com/ado/2009/02/edm/annotation");
ns.AddNamespace("", "http://schemas.microsoft.com/ado/2009/11/edm");
var entitySets = xdoc.SelectNodes("/edmx:Edmx/edmx:Runtime/edmx:ConceptualModels/Schema/EntityContainer/EntitySet", ns);
已从此工具获得XPath(http://qutoric.com/xmlquire/),因为我开始不相信自己的XPath技能,但它告诉我我已经使用了相同的XPath。
如果我删除“/模式/ EntityContainer相关/ EntitySet的”部分其寻找“/ EDMX:EDMX/EDMX:运行/ EDMX:ConceptualModels”,但不会进一步对已经尝试指定“EDMX “namespace(”edmx:/ Schema“)但没有区别。
希望你能帮助我,已经把我的头撞在桌子上。 :)
是否需要,如果没有蜜蜂的XPath,您可能需要使用LinqToXml – CSharpie