2017-06-18 40 views
0

我需要將StoreGeneratedPattern更新爲屬性節點的edmx文件programmaticaly中的「None」,基於某些criteara類似Name屬性包含「Code」值,將選擇這種Property元素的XPath是什麼?xpath讀取edmx文件EntityTypes

<?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" /> 

回答

0

嘗試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"); 
     } 
    } 
} 
+0

這是工作!謝謝 – Ashish