Beispiel #1
0
        /// <summary>复制数据表到另一个数据表,复制所有数据列、索引和关系</summary>
        /// <param name="src"></param>
        /// <param name="des"></param>
        /// <param name="resetColumnID">是否重置列ID</param>
        /// <returns></returns>
        public static IDataTable CopyAllFrom(this IDataTable src, IDataTable des, Boolean resetColumnID = false)
        {
            src.CopyFrom(des);
            src.Columns.AddRange(des.Columns.Select(i => src.CreateColumn().CopyFrom(i)));
            src.Indexes.AddRange(des.Indexes.Select(i => src.CreateIndex().CopyFrom(i)));
            src.Relations.AddRange(des.Relations.Select(i => src.CreateRelation().CopyFrom(i)));
            // 重载ID
            if (resetColumnID) src.Columns.ForEach((it, i) => it.ID = i + 1);

            return src;
        }
 public static void CreateColumn(this IAlterProcessor proc, ColumnInfo col)
 {
     proc.CreateColumn(col, null);
 }
 public static void CreateObject(this IAlterProcessor proc, DatabaseObjectInfo obj)
 {
     var tbl = obj as TableInfo;
     if (tbl != null)
     {
         proc.CreateTable(tbl);
         return;
     }
     var col = obj as ColumnInfo;
     if (col != null)
     {
         proc.CreateColumn(col);
         return;
     }
     var cnt = obj as ConstraintInfo;
     if (cnt != null)
     {
         proc.CreateConstraint(cnt);
         return;
     }
     var spe = obj as SpecificObjectInfo;
     if (spe != null)
     {
         proc.CreateSpecificObject(spe);
         return;
     }
     //var sch = obj as ISchemaStructure;
     //if (sch != null)
     //{
     //    proc.CreateSchema(sch);
     //    return;
     //}
     //var dom = obj as IDomainStructure;
     //if (dom != null)
     //{
     //    proc.CreateDomain(dom);
     //    return;
     //}
 }
Beispiel #4
0
        /// <summary>读取</summary>
        /// <param name="table"></param>
        /// <param name="reader"></param>
        /// <returns></returns>
        public static IDataTable ReadXml(this IDataTable table, XmlReader reader)
        {
            // 读属性
            if (reader.HasAttributes)
            {
                reader.MoveToFirstAttribute();
                //do
                //{
                //    switch (reader.Name)
                //    {
                //        case "ID":
                //            table.ID = reader.ReadContentAsInt();
                //            break;
                //        case "Name":
                //            table.Name = reader.ReadContentAsString();
                //            break;
                //        case "Alias":
                //            table.Alias = reader.ReadContentAsString();
                //            break;
                //        case "Owner":
                //            table.Owner = reader.ReadContentAsString();
                //            break;
                //        case "DbType":
                //            table.DbType = (DatabaseType)Enum.Parse(typeof(DatabaseType), reader.ReadContentAsString());
                //            break;
                //        case "IsView":
                //            table.IsView = Boolean.Parse(reader.ReadContentAsString());
                //            break;
                //        case "Description":
                //            table.Description = reader.ReadContentAsString();
                //            break;
                //        default:
                //            break;
                //    }
                //} while (reader.MoveToNextAttribute());
                ReadXml(reader, table);
            }

            reader.ReadStartElement();

            // 读字段
            reader.MoveToElement();
            while (reader.NodeType != XmlNodeType.EndElement)
            {
                switch (reader.Name)
                {
                    case "Columns":
                        reader.ReadStartElement();
                        while (reader.IsStartElement())
                        {
                            var dc = table.CreateColumn();
                            (dc as IXmlSerializable).ReadXml(reader);
                            table.Columns.Add(dc);
                        }
                        reader.ReadEndElement();
                        break;
                    case "Indexes":
                        reader.ReadStartElement();
                        while (reader.IsStartElement())
                        {
                            var di = table.CreateIndex();
                            (di as IXmlSerializable).ReadXml(reader);
                            table.Indexes.Add(di);
                        }
                        reader.ReadEndElement();
                        break;
                    case "Relations":
                        reader.ReadStartElement();
                        while (reader.IsStartElement())
                        {
                            var dr = table.CreateRelation();
                            (dr as IXmlSerializable).ReadXml(reader);
                            if (table.GetRelation(dr) == null) table.Relations.Add(dr);
                        }
                        reader.ReadEndElement();
                        break;
                    default:
                        break;
                }
            }

            //reader.ReadEndElement();
            if (reader.NodeType == XmlNodeType.EndElement) reader.ReadEndElement();

            return table;
        }