【问题标题】:xpath to read edmx file EntityTypes读取 edmx 文件 EntityTypes 的 xpath
【发布时间】:2017-11-20 20:52:13
【问题描述】:

我需要在 edmx 文件中以编程方式将属性节点的 StoreGeneratedPattern 更新为“None”,基于一些标准,例如 Name 属性包含“Code”值,选择此类 Property 元素的 XPath 将是什么?

<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="3.0" xmlns:edmx="http://schemas.microsoft.com/ado/2009/11/edmx">
  <!-- EF Runtime content -->
  <edmx:Runtime>
    <!-- SSDL content -->
    <edmx:StorageModels>
    <Schema Namespace="Model.Store" Provider="System.Data.CData.DynamicsCRM" ProviderManifestToken="DynamicsCRM" Alias="Self" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation" xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl">
        <EntityType Name="Account">
          <Key>
            <PropertyRef Name="Id" />
          </Key>
          <Property Name="Id" Type="varchar" StoreGeneratedPattern="Identity" Nullable="false" />
          <Property Name="AccountCategoryCode" Type="varchar" StoreGeneratedPattern="Computed" />
          <Property Name="AccountClassificationCode" Type="varchar" StoreGeneratedPattern="Computed" />
          <Property Name="AccountNumber" Type="varchar" />

【问题讨论】:

    标签: c# xml linq-to-xml edmx


    【解决方案1】:

    试试 xml linq

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml;
    using System.Xml.Linq;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            const string FILENAME = @"c:\temp\test.xml";
            static void Main(string[] args)
            {
                XDocument doc = XDocument.Load(FILENAME);
    
                XElement root = doc.Root;
    
    
                XElement entityType = root.Descendants().Where(x => x.Name.LocalName == "EntityType").FirstOrDefault();
                XNamespace ns = entityType.GetDefaultNamespace();
                XElement toChange = entityType.Elements(ns + "Property").Where(x => ((string)x.Attribute("Name")).Contains("Code")).FirstOrDefault();
                toChange.SetAttributeValue("StoreGeneratedPattern", "None");
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多