首页 > 代码库 > 从DACPAC文件中读取元数据
从DACPAC文件中读取元数据
SQL数据库项目生成时会生成dacpac文件,可从中读出所需的元数据,进行一些转换(如生成数据字典)
?
- var model = new TSqlModel(@"D:\kljob\CardLan\CardLanDB\bin\Debug\cardlandb.dacpac");
- ?
- XmlWriterSettings settings = new XmlWriterSettings();
- settings.Indent = true;
- settings.Encoding = new UTF8Encoding(false);
- settings.NewLineChars = Environment.NewLine;
- MemoryStream ms = new MemoryStream();
- XmlWriter writer=XmlWriter.Create(ms,settings);
- ?
- int startID=31;
- writer.WriteStartDocument();
- writer.WriteStartElement("root");
- foreach (var s in new ModelTypeClass[]{ModelSchema.Procedure ,ModelSchema.View}){
- ???var allTables = model.GetObjects(DacQueryScopes.UserDefined,s );
- ???var tableScripts = from t in allTables
- ???????????????select t ;
- ??????foreach(var x in tableScripts){
- ?????????writer.WriteStartElement("QueryObject");
- ?????????writer.WriteElementString("ObjectID",startID++.ToString());
- ?????????writer.WriteElementString("SourceType", x.ObjectType.Name);
- ?????????writer.WriteElementString("ObjectName", x.Name.Parts[1]);
- ?????????writer.WriteElementString("Remark","");
- ?
- ????????????int id=0;
- ????????????foreach(var c in x.GetChildren())
- ????????????{
- ???????????????writer.WriteStartElement("QueryObjectCols");
- ???????????????writer.WriteElementString("Title",c.Name.Parts[2]);
- ???????????????writer.WriteElementString("ObjColID",id++.ToString());
- ???????????????writer.WriteElementString("Field",c.Name.Parts[2]);
- ???????????????writer.WriteElementString("Width","80");
- ???????????????writer.WriteElementString("Sortable","1");
- ???????????????if(s==ModelSchema.Procedure)
- ??????????????????writer.WriteElementString("ValueType",c.GetReferenced(Parameter.DataType).First().Name.Parts[0]);
- ???????????????else
- ??????????????????writer.WriteElementString("ValueType",c.GetReferenced().First().GetReferenced(Column.DataType).First().Name.Parts[0]);
- ???????????????writer.WriteElementString("ShowOrder","1");
- ???????????????writer.WriteEndElement();
- ?
- ????????????}
- ?????????writer.WriteEndElement();
- ?????????break;
- ??????}
- ?
- ?}
- ?writer.WriteEndElement();
- ?writer.WriteEndDocument();
- writer.Close();
- string xml = Encoding.UTF8.GetString(ms.ToArray());
- Console.WriteLine(xml);
- //tableScripts.Dump();
?
?
?
?
从DACPAC文件中读取元数据
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。