zoukankan      html  css  js  c++  java
  • hibernate mapping文件中 xmlns会导致linq to xml 查询不到对应的节点

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Linq;
    using System.Xml.Linq;
    using System.Xml;
    using System.Windows.Forms;
    
    namespace ConsoleApplication27
    {
        class Program
        {
            [STAThread]
            static void Main(string[] args)
            {
                //<hibernate-mapping xmlns1="urn:nhibernate-mapping-2.2">
                //注意hibernate mapping文件中 xmlns会导致linq to xml 查询不到对应的节点,所以我吧xmlns改成xmlns1,事后自己再全文替换回来即可
                var path = AppDomain.CurrentDomain.BaseDirectory + "..\..\Mapping\PosPositionProductMapping2.hbm.xml";
    
                var root = XElement.Load(path);
    
                var cps = root.Elements("class").Elements("property").ToList();
                bool find1 = false;
                bool find2 = false;
                cps.ForEach(c =>
                {
                    string columnValue = c.Attribute("column").Value;
                    if (columnValue.ToLower().Contains("CREATED_EMPLOYEE_NAME".ToLower()))
                    {
                        
                        find1 = true;
                    }
                    if (c.Attribute("column").Value.ToLower().Contains("CREATED_EMPLOYEE_ID".ToLower()))
                    {
    
                        find2 = true;
                    }
                });
                XElement cls = root.Element("class");
                if (find1==false)
                {
                  
                  
                    XElement xe = new XElement("property",
                        new XAttribute("name","CreatedEmployeeName"),
                        new XAttribute("column", "CREATED_EMPLOYEE_NAME"),
                        new XAttribute("update","false")
    
                        );
    
                    cls.Add(xe);
                   
                }
                if (find2==false)
                {
    
    
                    XElement xe = new XElement("property",
                        new XAttribute("name", "CreatedEmployeeId"),
                        new XAttribute("column", "CREATED_EMPLOYEE_ID"),
                        new XAttribute("update", "false")
    
                        );
    
                    cls.Add(xe);
    
                }
                root.Save(path);
    
            }
        }
    }
  • 相关阅读:
    C#通过文件头判断图像格式(摘录)
    devenv.exe 应用程序错误
    LINQ TO SQL中的selectMany(转)
    DragDrop registration did not succeed. (摘录)
    API各函数作用简介(转)
    Linq递归用法(摘录)
    (转)逐步为对象集合构建一个通用的按指定属性排序的方法
    何止 Linq 的 Distinct 不给力(转)
    关于sql日志文件
    DES算法的C#实现
  • 原文地址:https://www.cnblogs.com/kexb/p/5448590.html
Copyright © 2011-2022 走看看