コード例 #1
0
        public override IReadOnlyList <DbGeneratedColumn> GetDbGeneratedColumns()
        {
            SchemaContext schemaContext = base.SchemaContextPool.Rent();

            try
            {
                var dbGeneratedColumns = new List <DbGeneratedColumn>();
                foreach (Column column in schemaContext.Columns.AsQueryable().Where(c => c.ColumnDefault != null))
                {
                    var dbGeneratedColumn = new DbGeneratedColumn()
                    {
                        ColumnName  = column.ColumnName,
                        TableName   = column.TableName,
                        TableSchema = column.TableSchema
                    };

                    if (column.ColumnDefault !.StartsWith("nextval("))
                    {
                        dbGeneratedColumn.IsIdentity = true;
                    }
                    else
                    {
                        dbGeneratedColumn.IsComputed = true;
                    }

                    dbGeneratedColumns.Add(dbGeneratedColumn);
                }
コード例 #2
0
        public override IReadOnlyList <DbGeneratedColumn> GetDbGeneratedColumns()
        {
            var schemaContext = base.GetSchemaContext();

            try
            {
                var dbGeneratedColumns = new List <DbGeneratedColumn>();
                var dbSet = schemaContext.Set <MySqlModelCustomizer.MySqlDbGeneratedColumn>();
                foreach (MySqlModelCustomizer.MySqlDbGeneratedColumn column in
                         dbSet.FromSqlRaw("SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, EXTRA FROM INFORMATION_SCHEMA.COLUMNS WHERE EXTRA <> ''"))
                {
                    var dbGeneratedColumn = new DbGeneratedColumn()
                    {
                        ColumnName  = column.ColumnName,
                        TableName   = column.TableName,
                        TableSchema = column.TableSchema
                    };

                    if (column.Extra == "auto_increment")
                    {
                        dbGeneratedColumn.IsIdentity = true;
                    }
                    else
                    {
                        dbGeneratedColumn.IsComputed = true;
                    }

                    dbGeneratedColumns.Add(dbGeneratedColumn);
                }
                return(dbGeneratedColumns);
            }
            finally
            {
                schemaContext.Dispose();
            }
        }