• 从DACPAC文件中读取元数据


    SQL数据库项目生成时会生成dacpac文件,可从中读出所需的元数据,进行一些转换(如生成数据字典)

     

    1. var model = new TSqlModel(@"D:kljobCardLanCardLanDBinDebugcardlandb.dacpac");
    2.  
    3. XmlWriterSettings settings = new XmlWriterSettings();
    4. settings.Indent = true;
    5. settings.Encoding = new UTF8Encoding(false);
    6. settings.NewLineChars = Environment.NewLine;
    7. MemoryStream ms = new MemoryStream();
    8. XmlWriter writer=XmlWriter.Create(ms,settings);
    9.  
    10. int startID=31;
    11. writer.WriteStartDocument();
    12. writer.WriteStartElement("root");
    13. foreach (var s in new ModelTypeClass[]{ModelSchema.Procedure ,ModelSchema.View}){
    14.    var allTables = model.GetObjects(DacQueryScopes.UserDefined,s );
    15.    var tableScripts = from t in allTables
    16.                select t ;
    17.       foreach(var x in tableScripts){
    18.          writer.WriteStartElement("QueryObject");
    19.          writer.WriteElementString("ObjectID",startID++.ToString());
    20.          writer.WriteElementString("SourceType", x.ObjectType.Name);
    21.          writer.WriteElementString("ObjectName", x.Name.Parts[1]);
    22.          writer.WriteElementString("Remark","");
    23.  
    24.             int id=0;
    25.             foreach(var c in x.GetChildren())
    26.             {
    27.                writer.WriteStartElement("QueryObjectCols");
    28.                writer.WriteElementString("Title",c.Name.Parts[2]);
    29.                writer.WriteElementString("ObjColID",id++.ToString());
    30.                writer.WriteElementString("Field",c.Name.Parts[2]);
    31.                writer.WriteElementString("Width","80");
    32.                writer.WriteElementString("Sortable","1");
    33.                if(s==ModelSchema.Procedure)
    34.                   writer.WriteElementString("ValueType",c.GetReferenced(Parameter.DataType).First().Name.Parts[0]);
    35.                else
    36.                   writer.WriteElementString("ValueType",c.GetReferenced().First().GetReferenced(Column.DataType).First().Name.Parts[0]);
    37.                writer.WriteElementString("ShowOrder","1");
    38.                writer.WriteEndElement();
    39.  
    40.             }
    41.          writer.WriteEndElement();
    42.          break;
    43.       }
    44.  
    45.  }
    46.  writer.WriteEndElement();
    47.  writer.WriteEndDocument();
    48. writer.Close();
    49. string xml = Encoding.UTF8.GetString(ms.ToArray());
    50. Console.WriteLine(xml);
    51. //tableScripts.Dump();

     

     

     

     

  • 相关阅读:
    js 中 undefined 和null 的区别
    【Gym103107E/黑龙江省赛16thE】Elastic Search(Trie树性质+ac自动机性质)
    不等概率抽卡的毕业期望次数
    博客园无法用IE进行登录
    Web项目开发小结
    各位看官,自己觉着喜欢的存到手机里面
    MVC控制器执行重定向
    吐了个槽o.o
    浏览器设置不缓存的方法
    关于A+B
  • 原文地址:https://www.cnblogs.com/QinQouShui/p/4059523.html
Copyright © 2020-2023  润新知