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();