Exemplo n.º 1
0
        public static DataTable SchemaFromStructure(this TableInfo tableStruct)
        {
            DataTable schema = CreateEmptySchema();
            int       index  = 1;

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

                row[SchemaTableColumn.ColumnName]           = col.Name;
                row[SchemaTableColumn.ColumnOrdinal]        = index;
                row[SchemaTableColumn.ColumnSize]           = 0;
                row[SchemaTableColumn.NumericPrecision]     = 0;
                row[SchemaTableColumn.NumericScale]         = 0;
                row[SchemaTableColumn.DataType]             = col.CommonType.DotNetType;
                row[SchemaTableColumn.ProviderType]         = (int)TypeTool.GetProviderType(col.CommonType.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.Name;

                schema.Rows.Add(row);

                index++;
            }
            return(schema);
        }
Exemplo n.º 2
0
        public static TableInfo GetTableInfo(this DataColumnCollection columns)
        {
            TableInfo res = new TableInfo(null);

            foreach (DataColumn col in columns.SortedByKey <DataColumn, int>(col => col.Ordinal))
            {
                var commonType = TypeTool.GetCommonType(col.DataType);
                var colInfo    = res.AddColumn(col.ColumnName, commonType.ToString(), TypeTool.GetCommonType(col.DataType));
                colInfo.NotNull = !col.AllowDBNull;
            }
            return(res);
        }