示例#1
0
        private async Task AddPrimaryKeysAsync(ModelBuilder builder, DbCommand command)
        {
            foreach (TupleData tuple in await TupleData.FromDbCommandAsync(command))
            {
                string tableName  = tuple["TABLE_NAME"] as string;
                string columnName = tuple["COLUMN_NAME"] as string;
                string keyName    = $"PK_{tableName}";
                int    keyIndex   = int.Parse(tuple["ORDINAL_POSITION"]?.ToString());

                builder.AddKey(null, tableName, columnName, keyName, keyIndex);
            }
        }
示例#2
0
        public async Task AddForeignKeysAsync(ModelBuilder builder, DbCommand command)
        {
            foreach (TupleData tuple in await TupleData.FromDbCommandAsync(command))
            {
                string tableName   = tuple["TABLE_NAME"] as string;
                string columnName  = tuple["COLUMN_NAME"] as string;
                string uniqueName  = $"PK_{tuple["REFERENCED_TABLE_NAME"]}";
                string foreignName = tuple["CONSTRAINT_NAME"] as string;
                int    keyIndex    = int.Parse(tuple["ORDINAL_POSITION"]?.ToString());

                builder.AddReference(null, tableName, columnName, foreignName, uniqueName, keyIndex);
            }
        }
示例#3
0
        private async Task AddTablesAndColumnsAsync(ModelBuilder builder, DbCommand command)
        {
            foreach (TupleData tuple in await TupleData.FromDbCommandAsync(command))
            {
                string tableName  = tuple["TABLE_NAME"] as string;
                string columnName = tuple["COLUMN_NAME"] as string;
                string typeName   = tuple["DATA_TYPE"] as string;
                bool   isNullable = (tuple["IS_NULLABLE"] as string == "YES");
                bool   isIdentity = ((string)tuple["EXTRA"]).Contains("auto_increment");

                builder.AddColumn(null, tableName, columnName, typeName, isNullable: isNullable, isIdentity: isIdentity);
            }
        }
示例#4
0
        public async Task AddForeignKeysAsync(ModelBuilder builder, DbCommand command)
        {
            foreach (TupleData tuple in await TupleData.FromDbCommandAsync(command))
            {
                string tableName   = tuple["tbl_name"] as string;
                string columnName  = tuple["from"] as string;
                string uniqueName  = $"pk_{tuple["table"]}";
                string foreignName = $"fk_{tableName}_{tuple["table"]}_{tuple["id"]}";
                int    keyIndex    = (int)(long)tuple["seq"] + 1;

                builder.AddReference(null, tableName, columnName, foreignName, uniqueName, keyIndex);
            }
        }
示例#5
0
        private async Task AddPrimaryKeysAsync(ModelBuilder builder, DbCommand command)
        {
            foreach (TupleData tuple in await TupleData.FromDbCommandAsync(command))
            {
                string tableSchema = tuple["table_schema"] as string;
                string tableName   = tuple["table_name"] as string;
                string columnName  = tuple["column_name"] as string;
                string keyName     = tuple["constraint_name"] as string;
                int    keyIndex    = int.Parse(tuple["ordinal_position"]?.ToString());

                builder.AddKey(tableSchema, tableName, columnName, keyName, keyIndex);
            }
        }
示例#6
0
        public async Task AddForeignKeysAsync(ModelBuilder builder, DbCommand command)
        {
            foreach (TupleData tuple in await TupleData.FromDbCommandAsync(command))
            {
                string tableSchema = null;
                string tableName   = tuple["TABLE_NAME"] as string;
                string columnName  = tuple["COLUMN_NAME"] as string;
                string uniqueName  = tuple["UNIQUE_CONSTRAINT_NAME"] as string;
                string foreignName = tuple["CONSTRAINT_NAME"] as string;
                int    keyIndex    = int.Parse(tuple["POSITION"]?.ToString());

                builder.AddReference(tableSchema, tableName, columnName, foreignName, uniqueName, keyIndex);
            }
        }
示例#7
0
        public async Task AddForeignKeysAsync(ModelBuilder builder, DbCommand command)
        {
            foreach (TupleData tuple in await TupleData.FromDbCommandAsync(command))
            {
                string tableSchema = tuple["table_schema"] as string;
                string tableName   = tuple["table_name"] as string;
                string columnName  = tuple["column_name"] as string;
                string uniqueName  = tuple["unique_constraint_name"] as string;
                string foreignName = tuple["constraint_name"] as string;
                int    keyIndex    = int.Parse(tuple["ordinal_position"]?.ToString());

                builder.AddReference(tableSchema, tableName, columnName, foreignName, uniqueName, keyIndex);
            }
        }
        private async Task AddTablesAndColumnsAsync(ModelBuilder builder, DbCommand command)
        {
            foreach (TupleData tuple in await TupleData.FromDbCommandAsync(command))
            {
                string tableSchema = tuple["TABLE_SCHEMA"] as string;
                string tableName   = tuple["TABLE_NAME"] as string;
                string columnName  = tuple["COLUMN_NAME"] as string;
                string typeName    = tuple["DATA_TYPE"] as string;
                bool   isNullable  = (tuple["IS_NULLABLE"] as string == "YES");
                bool   isIdentity  = ((int?)tuple["IS_IDENTITY"] == 1);
                bool   ignoreTable = this.IsIgnoredTable(tableSchema, tableName);

                builder.AddColumn(tableSchema, tableName, columnName, typeName, isNullable: isNullable, isIdentity: isIdentity, ignoreTable: ignoreTable);
            }
        }
示例#9
0
        private async Task AddTablesAndColumnAsync(ModelBuilder builder, DbCommand command)
        {
            foreach (TupleData tuple in await TupleData.FromDbCommandAsync(command))
            {
                string tableSchema = null;
                string tableName   = (tuple["TABLE_NAME"] as string).Trim();
                string columnName  = tuple["COLUMN_NAME"] as string;
                string typeName    = this.GetSanitizedDataType(tuple);
                bool   isNullable  = (tuple["NULLABLE"] as string == "Y");
                bool   isIdentity  = (tuple["IDENTITY_COLUMN"] as string == "YES");
                bool   ignoreTable = false;

                builder.AddColumn(tableSchema, tableName, columnName, typeName, isNullable: isNullable, isIdentity: isIdentity, ignoreTable: ignoreTable);
            }
        }
示例#10
0
        private async Task AddTablesAndColumnAsync(ModelBuilder builder, DbCommand command)
        {
            foreach (TupleData tuple in await TupleData.FromDbCommandAsync(command))
            {
                string tableSchema = tuple["table_schema"] as string;
                string tableName   = tuple["table_name"] as string;
                string columnName  = tuple["column_name"] as string;
                string typeName    = tuple["data_type"] as string;
                bool   isNullable  = (tuple["is_nullable"] as string == "YES");
                bool   isIdentity  = (tuple["is_identity"] as string == "YES" || tuple["serial_seq"] != null);
                bool   ignoreTable = false;

                builder.AddColumn(tableSchema, tableName, columnName, typeName, isNullable: isNullable, isIdentity: isIdentity, ignoreTable: ignoreTable);
            }
        }
示例#11
0
        private async Task AddTablesAndColumnsAsync(ModelBuilder builder, DbCommand command)
        {
            foreach (TupleData tuple in await TupleData.FromDbCommandAsync(command))
            {
                string sqlDef = tuple["sql"] as string;

                string tableName       = tuple["tbl_name"] as string;
                string columnName      = tuple["name"] as string;
                string typeName        = this.GetNormalizedTypeName(tuple);
                int    keyIndex        = (int)(long)tuple["pk"];
                bool   isAutoIncrement = keyIndex > 0 && ((long)tuple["autoincr"] > 0 || this.HasAutoIncrementInSqlDefinition(columnName, sqlDef));
                bool   isNullable      = (keyIndex == 0 && (long)tuple["notnull"] == 0);
                bool   ignoreTable     = this.IsIgnoredTable(tableName);

                builder.AddColumn(null, tableName, columnName, typeName, isNullable, isIdentity: isAutoIncrement, ignoreTable: ignoreTable);

                if (keyIndex > 0)
                {
                    builder.AddKey(null, tableName, columnName, "pk_" + tableName, (int)keyIndex);
                }
            }
        }