예제 #1
0
        public static DataTable SchemaFromStructure(this ITableStructure tableStruct)
        {
            DataTable schema = CreateEmptySchema();
            int       index  = 1;

            foreach (IColumnStructure col in tableStruct.Columns)
            {
                DataRow row = schema.NewRow();

                row[SchemaTableColumn.ColumnName]           = col.ColumnName;
                row[SchemaTableColumn.ColumnOrdinal]        = index;
                row[SchemaTableColumn.ColumnSize]           = 0;
                row[SchemaTableColumn.NumericPrecision]     = 0;
                row[SchemaTableColumn.NumericScale]         = 0;
                row[SchemaTableColumn.DataType]             = col.DataType.DotNetType;
                row[SchemaTableColumn.ProviderType]         = (int)TypeTool.GetProviderType(col.DataType.DotNetType);
                row[SchemaTableColumn.IsLong]               = false;
                row[SchemaTableColumn.AllowDBNull]          = true;
                row[SchemaTableOptionalColumn.IsReadOnly]   = false;
                row[SchemaTableOptionalColumn.IsRowVersion] = false;
                row[SchemaTableColumn.IsUnique]             = false;
                row[SchemaTableColumn.IsKey] = false;
                row[SchemaTableOptionalColumn.IsAutoIncrement] = false;
                row[SchemaTableColumn.BaseSchemaName]          = "";
                row[SchemaTableOptionalColumn.BaseCatalogName] = "";
                row[SchemaTableColumn.BaseTableName]           = "";
                row[SchemaTableColumn.BaseColumnName]          = col.ColumnName;

                schema.Rows.Add(row);

                index++;
            }
            return(schema);
        }
예제 #2
0
        public static ITableStructure GetTableStructure(this DataColumnCollection columns, string name)
        {
            TableStructure res = new TableStructure();

            //res.FilledMembers |= TableStructureMembers.ColumnNames | TableStructureMembers.ColumnTypes;
            foreach (DataColumn col in columns.SortedByKey <DataColumn, int>(col => col.Ordinal))
            {
                var c = res.AddColumn(col.ColumnName, TypeTool.GetDatAdminType(col.DataType));
                c.IsNullable   = col.AllowDBNull;
                c.DefaultValue = SqlExpression.ParseDefaultValue(col.DefaultValue.SafeToString(), null);
            }
            return(res);
        }
예제 #3
0
 public static DbTypeBase ReaderDataType(DataRow row)
 {
     try
     {
         string tp = row["DataTypeName"].SafeToString();
         if (tp == "xml")
         {
             return(new DbTypeXml());
         }
         int size = row.SafeString("ColumnSize").SafeIntParse();
         if (tp == "varchar")
         {
             return new DbTypeString {
                        Length = size
             }
         }
         ;
         if (tp == "nvarchar")
         {
             return new DbTypeString {
                        Length = size, IsUnicode = true
             }
         }
         ;
         if (tp == "text")
         {
             return(new DbTypeText());
         }
         if (tp == "ntext")
         {
             return new DbTypeText {
                        IsUnicode = true
             }
         }
         ;
     }
     catch { }
     return(TypeTool.GetDatAdminType((Type)row["DataType"]));
 }