How to request an EF model (EDMX document) using XPath

I am trying to write a utility that automatically sets an attribute ProviderManifestTokenin an EDMX document schema element, but even my basic XPath does not work. What am I doing wrong?

XML:

<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
  <!-- EF Runtime content -->
  <edmx:Runtime>
    <!-- SSDL content -->
    <edmx:StorageModels>
    <Schema Namespace="PvmmsModel.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2005

My attempt:

        var edmx = new XmlDocument();            
        edmx.Load(@"C:\Development\Provantage\PvmmsApp\Model.edmx");
        var nsm = new XmlNamespaceManager(edmx.NameTable);
        nsm.AddNamespace("edmx", "http://schemas.microsoft.com/ado/2007/06/edmx");

        var x = edmx.SelectSingleNode("//edmx:Edmx/edmx:Runtime/edmx:StorageModels", nsm);

This works, but as soon as I add Schemato the request. Then I get a null result.

+3
source share
1 answer

This is what the complete element looks like Schema(your fragment seems to be cropped);

<Schema xmlns="http://schemas.microsoft.com/ado/2009/02/edm/ssdl"
        Namespace="Model1.Store"
        Alias="Self"
        Provider="System.Data.SqlClient"
        ProviderManifestToken="2005">

Pay attention to the part xmlns. So this is actually in the namespace, despite the lack of a prefix.

, XPath, " - ". XPath :

...
nsm.AddNamespace("ssdl", "http://schemas.microsoft.com/ado/2009/02/edm/ssdl");
var x = edmx.SelectSingleNode(
    "//edmx:Edmx/edmx:Runtime/edmx:StorageModels/ssdl:Schema", nsm)
+7

Source: https://habr.com/ru/post/1748333/


All Articles