Beispiel #1
0
 public static void UpdateRow(this DbSchemaColumn item, DataRow row)
 {
     row.SetField(_SCHEMANAME, item.SchemaName);
     row.SetField(_TABLENAME, item.TableName);
     row.SetField(_COLUMNNAME, item.ColumnName);
     row.SetField(_DATATYPE, item.DataType);
     row.SetField(_LENGTH, item.Length);
     row.SetField(_NULLABLE, item.Nullable);
     row.SetField(_PRECISION, item.precision);
     row.SetField(_SCALE, item.scale);
     row.SetField(_ISPRIMARY, item.IsPrimary);
     row.SetField(_ISIDENTITY, item.IsIdentity);
     row.SetField(_ISCOMPUTED, item.IsComputed);
     row.SetField(_DEFINITION, item.definition);
     row.SetField(_PKCONTRAINTNAME, item.PKContraintName);
     row.SetField(_PK_SCHEMA, item.PK_Schema);
     row.SetField(_PK_TABLE, item.PK_Table);
     row.SetField(_PK_COLUMN, item.PK_Column);
     row.SetField(_FKCONTRAINTNAME, item.FKContraintName);
 }
Beispiel #2
0
 public static void FillObject(this DbSchemaColumn item, DataRow row)
 {
     item.SchemaName      = row.Field <string>(_SCHEMANAME);
     item.TableName       = row.Field <string>(_TABLENAME);
     item.ColumnName      = row.Field <string>(_COLUMNNAME);
     item.DataType        = row.Field <string>(_DATATYPE);
     item.Length          = row.Field <short>(_LENGTH);
     item.Nullable        = row.Field <bool>(_NULLABLE);
     item.precision       = row.Field <byte>(_PRECISION);
     item.scale           = row.Field <byte>(_SCALE);
     item.IsPrimary       = row.Field <bool>(_ISPRIMARY);
     item.IsIdentity      = row.Field <bool>(_ISIDENTITY);
     item.IsComputed      = row.Field <bool>(_ISCOMPUTED);
     item.definition      = row.Field <string>(_DEFINITION);
     item.PKContraintName = row.Field <string>(_PKCONTRAINTNAME);
     item.PK_Schema       = row.Field <string>(_PK_SCHEMA);
     item.PK_Table        = row.Field <string>(_PK_TABLE);
     item.PK_Column       = row.Field <string>(_PK_COLUMN);
     item.FKContraintName = row.Field <string>(_FKCONTRAINTNAME);
 }
Beispiel #3
0
 public static void CopyTo(this DbSchemaColumn from, DbSchemaColumn to)
 {
     to.SchemaName      = from.SchemaName;
     to.TableName       = from.TableName;
     to.ColumnName      = from.ColumnName;
     to.DataType        = from.DataType;
     to.Length          = from.Length;
     to.Nullable        = from.Nullable;
     to.precision       = from.precision;
     to.scale           = from.scale;
     to.IsPrimary       = from.IsPrimary;
     to.IsIdentity      = from.IsIdentity;
     to.IsComputed      = from.IsComputed;
     to.definition      = from.definition;
     to.PKContraintName = from.PKContraintName;
     to.PK_Schema       = from.PK_Schema;
     to.PK_Table        = from.PK_Table;
     to.PK_Column       = from.PK_Column;
     to.FKContraintName = from.FKContraintName;
 }
Beispiel #4
0
 public static bool CompareTo(this DbSchemaColumn a, DbSchemaColumn b)
 {
     return(a.SchemaName == b.SchemaName &&
            a.TableName == b.TableName &&
            a.ColumnName == b.ColumnName &&
            a.DataType == b.DataType &&
            a.Length == b.Length &&
            a.Nullable == b.Nullable &&
            a.precision == b.precision &&
            a.scale == b.scale &&
            a.IsPrimary == b.IsPrimary &&
            a.IsIdentity == b.IsIdentity &&
            a.IsComputed == b.IsComputed &&
            a.definition == b.definition &&
            a.PKContraintName == b.PKContraintName &&
            a.PK_Schema == b.PK_Schema &&
            a.PK_Table == b.PK_Table &&
            a.PK_Column == b.PK_Column &&
            a.FKContraintName == b.FKContraintName);
 }
Beispiel #5
0
 public static string ToSimpleString(this DbSchemaColumn obj)
 {
     return(string.Format("{{SchemaName:{0}, TableName:{1}, ColumnName:{2}, DataType:{3}, Length:{4}, Nullable:{5}, precision:{6}, scale:{7}, IsPrimary:{8}, IsIdentity:{9}, IsComputed:{10}, definition:{11}, PKContraintName:{12}, PK_Schema:{13}, PK_Table:{14}, PK_Column:{15}, FKContraintName:{16}}}",
                          obj.SchemaName,
                          obj.TableName,
                          obj.ColumnName,
                          obj.DataType,
                          obj.Length,
                          obj.Nullable,
                          obj.precision,
                          obj.scale,
                          obj.IsPrimary,
                          obj.IsIdentity,
                          obj.IsComputed,
                          obj.definition,
                          obj.PKContraintName,
                          obj.PK_Schema,
                          obj.PK_Table,
                          obj.PK_Column,
                          obj.FKContraintName));
 }
Beispiel #6
0
 public static IDictionary <String, Object> ToDictionary(this DbSchemaColumn item)
 {
     return(new Dictionary <string, object>()
     {
         [_SCHEMANAME] = item.SchemaName,
         [_TABLENAME] = item.TableName,
         [_COLUMNNAME] = item.ColumnName,
         [_DATATYPE] = item.DataType,
         [_LENGTH] = item.Length,
         [_NULLABLE] = item.Nullable,
         [_PRECISION] = item.precision,
         [_SCALE] = item.scale,
         [_ISPRIMARY] = item.IsPrimary,
         [_ISIDENTITY] = item.IsIdentity,
         [_ISCOMPUTED] = item.IsComputed,
         [_DEFINITION] = item.definition,
         [_PKCONTRAINTNAME] = item.PKContraintName,
         [_PK_SCHEMA] = item.PK_Schema,
         [_PK_TABLE] = item.PK_Table,
         [_PK_COLUMN] = item.PK_Column,
         [_FKCONTRAINTNAME] = item.FKContraintName
     });
 }
Beispiel #7
0
        /// <summary>
        /// create dbSchema from data with DataSet format
        /// </summary>
        /// <param name="ds"></param>
        public void AddSchema(DataSet ds)
        {
            DataTable dtSchema = DbSchemaColumnExtension.CreateTable();

            dbSchema.Tables.Add(dtSchema);

            dtSchema.TableName = ds.DataSetName;
            dtSchema.Namespace = ds.Namespace;

            foreach (DataTable dt in ds.Tables)
            {
                foreach (DataColumn column in dt.Columns)
                {
                    CType          cty     = column.DataType.ToCType();
                    DbSchemaColumn _column = new DbSchemaColumn
                    {
                        SchemaName      = dt.GetSchemaName(),
                        TableName       = dt.TableName,
                        ColumnName      = column.ColumnName,
                        DataType        = cty.GetSqlType(),
                        Length          = (short)column.MaxLength,
                        Nullable        = column.AllowDBNull,
                        precision       = 10,
                        scale           = 0,
                        IsPrimary       = dt.PrimaryKey.Contains(column),
                        IsIdentity      = column.AutoIncrement,
                        IsComputed      = false,
                        definition      = null,
                        PKContraintName = null,
                        PK_Schema       = null,
                        PK_Table        = null,
                        PK_Column       = null,
                        FKContraintName = null,
                    };

                    switch (cty)
                    {
                    case CType.Int:
                        _column.Length = 4;
                        break;

                    case CType.BigInt:
                        _column.Length = 8;
                        break;

                    case CType.NVarChar:
                    case CType.NText:
                    case CType.NChar:
                        _column.Length   *= 2;
                        _column.precision = 0;
                        break;

                    case CType.Bit:
                        _column.Length    = 1;
                        _column.precision = 1;
                        break;
                    }

                    if (_column.IsPrimary)
                    {
                        _column.PKContraintName = $"PK_{dtSchema.TableName.ToIdent()}";
                    }

                    var newRow = dtSchema.NewRow();
                    _column.UpdateRow(newRow);
                    dtSchema.Rows.Add(newRow);
                }
            }
        }