コード例 #1
1
        public override void ColumnDefinition(
            string schema, 
            string table, 
            string name, 
            string type, 
            bool nullable, 
            object defaultValue, 
            string defaultValueSql,
            string computedColumnSql, 
            IAnnotatable annotatable, 
            IModel model, 
            SqlBatchBuilder builder)
        {
            base.ColumnDefinition(
                schema, table, name, type, nullable, 
                defaultValue, defaultValueSql, computedColumnSql, annotatable, model, builder);

            var columnAnnotation = annotatable as Annotatable;
            var inlinePk = columnAnnotation?.FindAnnotation(SqliteAnnotationNames.Prefix + SqliteAnnotationNames.InlinePrimaryKey);

            if (inlinePk != null
                && (bool)inlinePk.Value)
            {
                builder.Append(" PRIMARY KEY");
                var autoincrement = columnAnnotation.FindAnnotation(SqliteAnnotationNames.Prefix + SqliteAnnotationNames.Autoincrement);
                if (autoincrement != null
                    && (bool)autoincrement.Value)
                {
                    builder.Append(" AUTOINCREMENT");
                }
            }
        }
コード例 #2
0
        protected virtual void ColumnDefinition(
            [CanBeNull] string schema,
            [NotNull] string table,
            [NotNull] string name,
            [NotNull] Type clrType,
            [CanBeNull] string type,
            bool nullable,
            [CanBeNull] object defaultValue,
            [CanBeNull] string defaultValueSql,
            [CanBeNull] string computedColumnSql,
            bool identity,
            [NotNull] IAnnotatable annotatable,
            [CanBeNull] IModel model,
            [NotNull] MigrationCommandListBuilder builder)
        {
            Check.NotEmpty(name, nameof(name));
            Check.NotNull(clrType, nameof(clrType));
            Check.NotNull(annotatable, nameof(annotatable));
            Check.NotNull(builder, nameof(builder));

            if (computedColumnSql != null)
            {
                builder
                .Append(SqlGenerationHelper.DelimitIdentifier(name))
                .Append(" AS ")
                .Append(computedColumnSql);

                return;
            }

            base.ColumnDefinition(
                schema,
                table,
                name,
                clrType,
                type,
                nullable,
                defaultValue,
                defaultValueSql,
                computedColumnSql,
                annotatable,
                model,
                builder);

            if (identity)
            {
                builder.Append(" IDENTITY");
            }
        }
コード例 #3
0
        public override void ColumnDefinition(
            string schema,
            string table,
            string name,
            string type,
            bool nullable,
            object defaultValue,
            string defaultExpression,
            IAnnotatable annotatable,
            IModel model,
            SqlBatchBuilder builder)
        {
            Check.NotEmpty(name, nameof(name));
            Check.NotEmpty(type, nameof(type));
            Check.NotNull(annotatable, nameof(annotatable));
            Check.NotNull(builder, nameof(builder));

            var computedExpression = annotatable[SqlServerAnnotationNames.Prefix
                                                 + SqlServerAnnotationNames.ColumnComputedExpression];

            if (computedExpression != null)
            {
                builder
                .Append(_sql.DelimitIdentifier(name))
                .Append(" AS ")
                .Append(computedExpression);

                return;
            }

            base.ColumnDefinition(
                schema,
                table,
                name,
                type,
                nullable,
                defaultValue,
                defaultExpression,
                annotatable,
                model,
                builder);

            var valueGeneration = (string)annotatable[SqlServerAnnotationNames.Prefix + SqlServerAnnotationNames.ValueGeneration];

            if (valueGeneration == "Identity")
            {
                builder.Append(" IDENTITY");
            }
        }
コード例 #4
0
        /// <summary>
        /// Generates a SQL fragment for a column definition for the given column metadata.
        /// </summary>
        /// <param name="schema">
        /// The schema that contains the table, or <c>null</c> to use the default schema.
        /// </param>
        /// <param name="table">The table that contains the column.</param>
        /// <param name="name">The column name.</param>
        /// <param name="clrType">The CLR <see cref="Type"/> that the column is mapped to.</param>
        /// <param name="type">
        /// The database/store type for the column, or <c>null</c> if none has been specified.
        /// </param>
        /// <param name="unicode">
        /// Indicates whether or not the column can contain Unicode data, or <c>null</c> if this is
        /// not applicable or not specified.
        /// </param>
        /// <param name="maxLength">
        /// The maximum amount of data that the column can contain, or <c>null</c> if this is not
        /// applicable or not specified.
        /// </param>
        /// <param name="fixedLength">
        /// Indicates whether or not the column is constrained to fixed-length data.
        /// </param>
        /// <param name="rowVersion">
        /// Indicates whether or not this column is an automatic concurrency token, such as a SQL
        /// Server timestamp/rowversion.
        /// </param>
        /// <param name="nullable">Indicates whether or not the column can store <c>NULL</c> values.</param>
        /// <param name="defaultValue">The default value for the column.</param>
        /// <param name="defaultValueSql">The SQL expression to use for the column's default constraint.</param>
        /// <param name="computedColumnSql">The SQL expression to use to compute the column value.</param>
        /// <param name="annotatable">
        /// The <see cref="MigrationOperation"/> to use to find any custom annotations.
        /// </param>
        /// <param name="model">
        /// The target model which may be <c>null</c> if the operations exist without a model.
        /// </param>
        /// <param name="builder">The command builder to use to add the SQL fragment.</param>
        protected override void ColumnDefinition(
            string schema,
            string table,
            string name,
            Type clrType,
            string type,
            bool?unicode,
            int?maxLength,
            bool?fixedLength,
            bool rowVersion,
            bool nullable,
            object defaultValue,
            string defaultValueSql,
            string computedColumnSql,
            IAnnotatable annotatable,
            IModel model,
            MigrationCommandListBuilder builder)
        {
            base.ColumnDefinition(
                schema, table, name, clrType, type, unicode, maxLength, fixedLength, rowVersion, nullable,
                defaultValue, defaultValueSql, computedColumnSql, annotatable, model, builder);

            var inlinePk = annotatable[SqliteAnnotationNames.InlinePrimaryKey] as bool?;

            if (inlinePk == true)
            {
                var inlinePkName = annotatable[
                    SqliteAnnotationNames.InlinePrimaryKeyName] as string;
                if (!string.IsNullOrEmpty(inlinePkName))
                {
                    builder
                    .Append(" CONSTRAINT ")
                    .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(inlinePkName));
                }

                builder.Append(" PRIMARY KEY");
                var autoincrement = annotatable[SqliteAnnotationNames.Autoincrement] as bool?
                                    // NB: Migrations scaffolded with version 1.0.0 don't have the
                                    // prefix. See #6461
                                    ?? annotatable[SqliteAnnotationNames.LegacyAutoincrement] as bool?;
                if (autoincrement == true)
                {
                    builder.Append(" AUTOINCREMENT");
                }
            }
        }
コード例 #5
0
 private static void AddMatchingPredecessorEdge(
     Dictionary <IKeyValueIndex, List <ModificationCommand> > predecessorsMap,
     IKeyValueIndex dependentKeyValue,
     Multigraph <ModificationCommand, IAnnotatable> commandGraph,
     ModificationCommand command,
     IAnnotatable edge)
 {
     if (predecessorsMap.TryGetValue(dependentKeyValue, out var predecessorCommands))
     {
         foreach (var predecessor in predecessorCommands)
         {
             if (predecessor != command)
             {
                 commandGraph.AddEdge(predecessor, command, edge);
             }
         }
     }
 }
コード例 #6
0
 private static void AddMatchingPredecessorEdge <T>(
     Dictionary <T, List <ModificationCommand> > predecessorsMap,
     T keyValue,
     Multigraph <ModificationCommand, IAnnotatable> commandGraph,
     ModificationCommand command,
     IAnnotatable edge)
     where T : notnull
 {
     if (predecessorsMap.TryGetValue(keyValue, out var predecessorCommands))
     {
         foreach (var predecessor in predecessorCommands)
         {
             if (predecessor != command)
             {
                 commandGraph.AddEdge(predecessor, command, edge);
             }
         }
     }
 }
コード例 #7
0
        public virtual void ColumnDefinition(
            [CanBeNull] string schema,
            [CanBeNull] string table,
            [NotNull] string name,
            [NotNull] string type,
            bool nullable,
            [CanBeNull] object defaultValue,
            [CanBeNull] string defaultValueSql,
            [CanBeNull] string computedColumnSql,
            [NotNull] IAnnotatable annotatable,
            [CanBeNull] IModel model,
            [NotNull] SqlBatchBuilder builder)
        {
            Check.NotEmpty(name, nameof(name));
            Check.NotEmpty(type, nameof(type));
            Check.NotNull(annotatable, nameof(annotatable));
            Check.NotNull(builder, nameof(builder));

            builder
            .Append(_sql.DelimitIdentifier(name))
            .Append(" ")
            .Append(type);

            if (!nullable)
            {
                builder.Append(" NOT NULL");
            }

            if (defaultValueSql != null)
            {
                builder
                .Append(" DEFAULT (")
                .Append(defaultValueSql)
                .Append(")");
            }
            else if (defaultValue != null)
            {
                builder
                .Append(" DEFAULT ")
                .Append(_sql.GenerateLiteral((dynamic)defaultValue));
            }
        }
コード例 #8
0
        /// <summary>
        /// 列定义。
        /// </summary>
        /// <param name="table">表格。</param>
        /// <param name="name">名称。</param>
        /// <param name="clrType">CLR类型。</param>
        /// <param name="type">字段类型。</param>
        /// <param name="unicode">是否Unicode字符集。</param>
        /// <param name="maxLength">大小。</param>
        /// <param name="rowVersion">是否为RowVersion列。</param>
        /// <param name="identity">是否自增长。</param>
        /// <param name="nullable">是否可空。</param>
        /// <param name="defaultValue">默认值。</param>
        /// <param name="defaultValueSql">默认SQL字符串。</param>
        /// <param name="computedColumnSql">计算列的SQL字符串。</param>
        /// <param name="annotatable">扩展实例。</param>
        /// <param name="builder"><see cref="MigrationCommandListBuilder"/>实例。</param>
        protected override void ColumnDefinition(ITable table, string name, Type clrType, string type, bool?unicode, int?maxLength,
                                                 bool rowVersion, bool identity, bool nullable, object defaultValue, string defaultValueSql, string computedColumnSql,
                                                 IAnnotatable annotatable, MigrationCommandListBuilder builder)
        {
            if (computedColumnSql != null)
            {
                builder
                .Append(SqlHelper.DelimitIdentifier(name))
                .Append(" AS ")
                .Append(computedColumnSql);

                return;
            }

            base.ColumnDefinition(table, name, clrType, type, unicode, maxLength, rowVersion, identity, nullable, defaultValue, defaultValueSql, computedColumnSql, annotatable, builder);

            if (identity)
            {
                builder.Append(" IDENTITY");
            }
        }
コード例 #9
0
        public static void SetAnnotation <TValue>([NotNull] this IAnnotatable annotatable,
                                                  [NotNull] string annotationName,
                                                  [CanBeNull] TValue value)
        {
            Check.NotNull(annotatable, nameof(annotatable));
            if (string.IsNullOrWhiteSpace(annotationName))
            {
                throw new ArgumentException(message: "Annotation name cannot be null, empty, or exclusively white-space.", paramName: nameof(annotationName));
            }
            var mutableAnnotatable = annotatable as IMutableAnnotatable;

            if (mutableAnnotatable == null)
            {
                throw new InvalidOperationException($"Annotable object must be an instance of {nameof(IMutableAnnotatable)}.");
            }
            mutableAnnotatable.RemoveAnnotation(annotationName);
            if (value != null)
            {
                mutableAnnotatable.AddAnnotation(annotationName, value);
            }
        }
コード例 #10
0
        protected override void ColumnDefinition(
            string schema,
            string table,
            string name,
            Type clrType,
            string type,
            bool?unicode,
            int?maxLength,
            bool?fixedLength,
            bool rowVersion,
            bool nullable,
            object defaultValue,
            string defaultValueSql,
            string computedColumnSql,
            IAnnotatable annotatable,
            IModel model,
            MigrationCommandListBuilder builder)
        {
            var valueGenerationStrategy = annotatable[
                OracleAnnotationNames.ValueGenerationStrategy] as OracleValueGenerationStrategy?;

            ColumnDefinition(
                schema,
                table,
                name,
                clrType,
                type,
                unicode,
                maxLength,
                fixedLength,
                rowVersion,
                nullable,
                defaultValue,
                defaultValueSql,
                computedColumnSql,
                valueGenerationStrategy == OracleValueGenerationStrategy.IdentityColumn,
                annotatable,
                model,
                builder);
        }
コード例 #11
0
        protected virtual void ColumnDefinition(
            [CanBeNull] string schema,
            [NotNull] string table,
            [NotNull] string name,
            [NotNull] Type clrType,
            [CanBeNull] string type,
            bool nullable,
            [CanBeNull] object defaultValue,
            [CanBeNull] string defaultValueSql,
            [CanBeNull] string computedColumnSql,
            [NotNull] IAnnotatable annotatable,
            [CanBeNull] IModel model,
            [NotNull] MigrationCommandListBuilder builder)
        {
            Check.NotEmpty(name, nameof(name));
            Check.NotNull(clrType, nameof(clrType));
            Check.NotNull(annotatable, nameof(annotatable));
            Check.NotNull(builder, nameof(builder));

            if (type == null)
            {
                var property = FindProperty(model, schema, table, name);
                type = property != null
                    ? TypeMapper.GetMapping(property).DefaultTypeName
                    : TypeMapper.GetMapping(clrType).DefaultTypeName;
            }

            builder
            .Append(SqlGenerationHelper.DelimitIdentifier(name))
            .Append(" ")
            .Append(type);

            if (!nullable)
            {
                builder.Append(" NOT NULL");
            }

            DefaultValue(defaultValue, defaultValueSql, builder);
        }
コード例 #12
0
        protected override void ColumnDefinition(
            string schema,
            string table,
            string name,
            Type clrType,
            string type,
            bool nullable,
            object defaultValue,
            string defaultValueSql,
            string computedColumnSql,
            IAnnotatable annotatable,
            IModel model,
            RelationalCommandListBuilder builder)
        {
            base.ColumnDefinition(
                schema, table, name, clrType, type, nullable,
                defaultValue, defaultValueSql, computedColumnSql, annotatable, model, builder);

            var inlinePk = annotatable[SqliteFullAnnotationNames.Instance.InlinePrimaryKey] as bool?;

            if (inlinePk == true)
            {
                var inlinePkName = annotatable[
                    SqliteFullAnnotationNames.Instance.InlinePrimaryKeyName] as string;
                if (!string.IsNullOrEmpty(inlinePkName))
                {
                    builder
                    .Append(" CONSTRAINT ")
                    .Append(SqlGenerationHelper.DelimitIdentifier(inlinePkName));
                }
                builder.Append(" PRIMARY KEY");
                var autoincrement = annotatable[SqliteFullAnnotationNames.Instance.Autoincrement] as bool?;
                if (autoincrement == true)
                {
                    builder.Append(" AUTOINCREMENT");
                }
            }
        }
コード例 #13
0
        protected override void ColumnDefinition(
            string schema,
            string table,
            string name,
            Type clrType,
            string type,
            bool nullable,
            object defaultValue,
            string defaultValueSql,
            string computedColumnSql,
            IAnnotatable annotatable,
            IModel model,
            SqlBatchBuilder builder)
        {
            base.ColumnDefinition(
                schema, table, name, clrType, type, nullable,
                defaultValue, defaultValueSql, computedColumnSql, annotatable, model, builder);

            var inlinePk = annotatable[SqliteAnnotationNames.Prefix + SqliteAnnotationNames.InlinePrimaryKey] as bool?;
            if (inlinePk == true)
            {
                var inlinePkName = annotatable[
                    SqliteAnnotationNames.Prefix + SqliteAnnotationNames.InlinePrimaryKeyName] as string;
                if (!string.IsNullOrEmpty(inlinePkName))
                {
                    builder
                        .Append(" CONSTRAINT ")
                        .Append(Sql.DelimitIdentifier(inlinePkName));
                }
                builder.Append(" PRIMARY KEY");
                var autoincrement = annotatable[SqliteAnnotationNames.Prefix + SqliteAnnotationNames.Autoincrement] as bool?;
                if (autoincrement == true)
                {
                    builder.Append(" AUTOINCREMENT");
                }
            }
        }
コード例 #14
0
        protected override void ColumnDefinition(
            string schema,
            string table,
            string name,
            Type clrType,
            string type,
            bool?unicode,
            int?maxLength,
            bool rowVersion,
            bool nullable,
            object defaultValue,
            string defaultValueSql,
            string computedColumnSql,
            IAnnotatable annotatable,
            IModel model,
            MigrationCommandListBuilder builder)
        {
            var valueGeneration = (string)annotatable[SqlCeAnnotationNames.Prefix + SqlCeAnnotationNames.ValueGeneration];

            ColumnDefinition(
                schema,
                table,
                name,
                clrType,
                type,
                unicode,
                maxLength,
                rowVersion,
                nullable,
                defaultValue,
                defaultValueSql,
                computedColumnSql,
                valueGeneration == SqlCeAnnotationNames.Identity,
                annotatable,
                model,
                builder);
        }
コード例 #15
0
        /// <summary>
        ///     This API supports the Entity Framework Core infrastructure and is not intended to be used
        ///     directly from your code. This API may change or be removed in future releases.
        /// </summary>
        public static string AnnotationsToDebugString([NotNull] this IAnnotatable annotatable, [NotNull] string indent = "")
        {
            var annotations = annotatable.GetAnnotations().ToList();

            if (annotations.Count == 0)
            {
                return("");
            }
            var builder = new StringBuilder();

            builder.AppendLine().Append(indent).Append("Annotations: ");
            foreach (var annotation in annotations)
            {
                builder
                .AppendLine()
                .Append(indent)
                .Append("  ")
                .Append(annotation.Name)
                .Append(": ")
                .Append(annotation.Value);
            }

            return(builder.ToString());
        }
コード例 #16
0
        protected override void ColumnDefinition(
            [CanBeNull] string schema,
            [NotNull] string table,
            [NotNull] string name,
            [NotNull] Type clrType,
            [CanBeNull] string type,
            bool?unicode,
            int?maxLength,
            bool?fixedLength,
            bool rowVersion,
            bool nullable,
            [CanBeNull] object defaultValue,
            [CanBeNull] string defaultValueSql,
            [CanBeNull] string computedColumnSql,
            [NotNull] IAnnotatable annotatable,
            [CanBeNull] IModel model,
            [NotNull] MigrationCommandListBuilder builder)
        {
            Check.NotEmpty(name, nameof(name));
            Check.NotNull(clrType, nameof(clrType));
            Check.NotNull(annotatable, nameof(annotatable));
            Check.NotNull(builder, nameof(builder));

            if (type == null)
            {
                type = GetColumnType(schema, table, name, clrType, unicode, maxLength, fixedLength, rowVersion, model);
            }
            builder
            .Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(name))
            .Append(" ")
            .Append(type);

            builder.Append(nullable ? " NULL" : " NOT NULL");

            DefaultValue(defaultValue, defaultValueSql, builder);
        }
コード例 #17
0
        /// <summary>
        /// 列定义。
        /// </summary>
        /// <param name="table">表格。</param>
        /// <param name="name">名称。</param>
        /// <param name="clrType">CLR类型。</param>
        /// <param name="type">字段类型。</param>
        /// <param name="unicode">是否Unicode字符集。</param>
        /// <param name="maxLength">大小。</param>
        /// <param name="rowVersion">是否为RowVersion列。</param>
        /// <param name="identity">是否自增长。</param>
        /// <param name="nullable">是否可空。</param>
        /// <param name="defaultValue">默认值。</param>
        /// <param name="defaultValueSql">默认SQL字符串。</param>
        /// <param name="computedColumnSql">计算列的SQL字符串。</param>
        /// <param name="annotatable">扩展实例。</param>
        /// <param name="builder"><see cref="MigrationCommandListBuilder"/>实例。</param>
        protected virtual void ColumnDefinition(
            [NotNull] ITable table,
            [NotNull] string name,
            [NotNull] Type clrType,
            [CanBeNull] string type,
            [CanBeNull] bool?unicode,
            [CanBeNull] int?maxLength,
            bool rowVersion,
            bool identity,
            bool nullable,
            [CanBeNull] object defaultValue,
            [CanBeNull] string defaultValueSql,
            [CanBeNull] string computedColumnSql,
            [NotNull] IAnnotatable annotatable,
            [NotNull] MigrationCommandListBuilder builder)
        {
            Check.NotEmpty(name, nameof(name));
            Check.NotNull(clrType, nameof(clrType));
            Check.NotNull(annotatable, nameof(annotatable));
            Check.NotNull(builder, nameof(builder));

            builder
            .Append(SqlHelper.DelimitIdentifier(name))
            .Append(" ")
            .Append(type ?? TypeMapper.GetMapping(clrType, maxLength, rowVersion, unicode));

            if (!nullable)
            {
                builder.Append(" NOT NULL");
            }

            if (!identity)
            {
                DefaultValue(defaultValue, defaultValueSql, builder);
            }
        }
コード例 #18
0
        /// <summary>
        /// Adds the annotation of type TElement in the <paramref name="annotatable"/> (if it exists) to the <paramref name="payloadElement"/>.
        /// </summary>
        /// <typeparam name="TElement">The type of the payload element to work with.</typeparam>
        /// <param name="payloadElement">The payload element to add the annotation to.</param>
        /// <param name="annotatable">The annotatable that potentially holds the annotation to add.</param>
        /// <returns>The <paramref name="payloadElement"/> after the annotation was added.</returns>
        public static TElement CopyAnnotation <TElement, TAnnotation>(this TElement payloadElement, IAnnotatable <ODataPayloadElementAnnotation> annotatable)
            where TElement : ODataPayloadElement
            where TAnnotation : ODataPayloadElementAnnotation
        {
            ExceptionUtilities.CheckArgumentNotNull(payloadElement, "payloadElement");
            ExceptionUtilities.CheckArgumentNotNull(annotatable, "annotatable");

            TAnnotation annotation = (TAnnotation)annotatable.GetAnnotation(typeof(TAnnotation));

            if (annotation != null)
            {
                payloadElement.AddAnnotation(annotation);
            }

            return(payloadElement);
        }
 private static bool IsMemoryOptimized([NotNull] IAnnotatable annotatable)
 => annotatable[SqlServerAnnotationNames.MemoryOptimized] as bool? == true;
コード例 #20
0
        protected override void ColumnDefinition(
            string schema,
            string table,
            string name,
            Type clrType,
            string type,
            bool nullable,
            object defaultValue,
            string defaultValueSql,
            string computedColumnSql,
            IAnnotatable annotatable,
            IModel model,
            RelationalCommandListBuilder builder)
        {
            var valueGenerationStrategy = annotatable[
                SqlServerAnnotationNames.Prefix + SqlServerAnnotationNames.ValueGenerationStrategy] as SqlServerValueGenerationStrategy?;

            ColumnDefinition(
                schema,
                table,
                name,
                clrType,
                type,
                nullable,
                defaultValue,
                defaultValueSql,
                computedColumnSql,
                valueGenerationStrategy == SqlServerValueGenerationStrategy.IdentityColumn,
                annotatable,
                model,
                builder);
        }
コード例 #21
0
        /// <summary>
        ///     Constructs a new helper for the given <see cref="IAnnotatable" /> metadata item.
        /// </summary>
        /// <param name="metadata"> The metadata item to be annotated. </param>
        public RelationalAnnotations([NotNull] IAnnotatable metadata)
        {
            Check.NotNull(metadata, nameof(metadata));

            Metadata = metadata;
        }
 internal PostgresExtension(IAnnotatable annotatable, string annotationName)
 {
     _annotatable    = annotatable;
     _annotationName = annotationName;
 }
コード例 #23
0
 /// <summary>
 /// Creates a <see cref="PostgresExtension"/>.
 /// </summary>
 /// <param name="annotatable">The annotatable to search for the annotation.</param>
 /// <param name="annotationName">The annotation name to search for in the annotatable.</param>
 /// <exception cref="ArgumentNullException"><paramref name="annotatable"/></exception>
 /// <exception cref="ArgumentNullException"><paramref name="annotationName"/></exception>
 internal PostgresExtension([NotNull] IAnnotatable annotatable, [NotNull] string annotationName)
 {
     _annotatable    = Check.NotNull(annotatable, nameof(annotatable));
     _annotationName = Check.NotNull(annotationName, nameof(annotationName));
 }
コード例 #24
0
 /// <summary>
 /// Sets annotation of a JsonAnnotation annotatable.
 /// </summary>
 /// <typeparam name="T">The type of the annotation to set.</typeparam>
 /// <param name="annotatable">The annotatable to set the annotation on.</param>
 /// <param name="annotation">The annotation to set.</param>
 public static void SetAnnotation <T>(this IAnnotatable <JsonAnnotation> annotatable, T annotation) where T : JsonAnnotation
 {
     annotatable.SetAnnotation <T, JsonAnnotation>(annotation);
 }
コード例 #25
0
        public override void ColumnDefinition(
            string schema,
            string table,
            string name,
            string type,
            bool nullable,
            object defaultValue,
            string defaultExpression,
            IAnnotatable annotatable,
            IModel model,
            SqlBatchBuilder builder)
        {
            Check.NotEmpty(name, nameof(name));
            Check.NotEmpty(type, nameof(type));
            Check.NotNull(annotatable, nameof(annotatable));
            Check.NotNull(builder, nameof(builder));

            var computedExpression = annotatable[SqlServerAnnotationNames.Prefix
                + SqlServerAnnotationNames.ColumnComputedExpression];
            if (computedExpression != null)
            {
                builder
                    .Append(_sql.DelimitIdentifier(name))
                    .Append(" AS ")
                    .Append(computedExpression);

                return;
            }

            base.ColumnDefinition(
                schema,
                table,
                name,
                type,
                nullable,
                defaultValue,
                defaultExpression,
                annotatable,
                model,
                builder);

            var valueGeneration = (string)annotatable[SqlServerAnnotationNames.Prefix + SqlServerAnnotationNames.ValueGeneration];
            if (valueGeneration == "Identity")
            {
                builder.Append(" IDENTITY");
            }
        }
コード例 #26
0
        protected override void ColumnDefinition(
            string schema,
            string table,
            string name,
            Type clrType,
            string type,
            bool nullable,
            object defaultValue,
            string defaultValueSql,
            string computedColumnSql,
            IAnnotatable annotatable,
            IModel model,
            SqlBatchBuilder builder)
        {
            Check.NotEmpty(name, nameof(name));
            Check.NotNull(clrType, nameof(clrType));
            Check.NotNull(annotatable, nameof(annotatable));
            Check.NotNull(builder, nameof(builder));

            if (computedColumnSql != null)
            {
                builder
                    .Append(Sql.DelimitIdentifier(name))
                    .Append(" AS ")
                    .Append(computedColumnSql);

                return;
            }

            base.ColumnDefinition(
                schema,
                table,
                name,
                clrType,
                type,
                nullable,
                defaultValue,
                defaultValueSql,
                computedColumnSql,
                annotatable,
                model,
                builder);

            var valueGenerationStrategy = annotatable[
                SqlServerAnnotationNames.Prefix + SqlServerAnnotationNames.ValueGenerationStrategy] as SqlServerIdentityStrategy?;
            if (valueGenerationStrategy == SqlServerIdentityStrategy.IdentityColumn)
            {
                builder.Append(" IDENTITY");
            }
        }
コード例 #27
0
        protected override void ColumnDefinition(
            string schema,
            string table,
            string name,
            Type clrType,
            string type,
            bool? unicode,
            int? maxLength,
            bool rowVersion,
            bool nullable,
            object defaultValue,
            string defaultValueSql,
            string computedColumnSql,
            IAnnotatable annotatable,
            IModel model,
            MigrationCommandListBuilder builder)
        {
            base.ColumnDefinition(
                schema, table, name, clrType, type, unicode, maxLength, rowVersion, nullable,
                defaultValue, defaultValueSql, computedColumnSql, annotatable, model, builder);

            var inlinePk = annotatable[SqliteFullAnnotationNames.Instance.InlinePrimaryKey] as bool?;
            if (inlinePk == true)
            {
                var inlinePkName = annotatable[
                    SqliteFullAnnotationNames.Instance.InlinePrimaryKeyName] as string;
                if (!string.IsNullOrEmpty(inlinePkName))
                {
                    builder
                        .Append(" CONSTRAINT ")
                        .Append(SqlGenerationHelper.DelimitIdentifier(inlinePkName));
                }
                builder.Append(" PRIMARY KEY");
                var autoincrement = annotatable[SqliteFullAnnotationNames.Instance.Autoincrement] as bool?;
                if (autoincrement == true)
                {
                    builder.Append(" AUTOINCREMENT");
                }
            }
        }
コード例 #28
0
 /// <summary>
 /// Gets annotation from a JsonAnnotation annotatable.
 /// </summary>
 /// <typeparam name="T">The type of the annotation to get.</typeparam>
 /// <param name="annotatable">The annotatable to get the annotation from.</param>
 /// <returns>The annotation or null if there's no such annotation.</returns>
 public static T GetAnnotation <T>(this IAnnotatable <JsonAnnotation> annotatable) where T : JsonAnnotation
 {
     return((T)annotatable.GetAnnotation(typeof(T)));
 }
コード例 #29
0
ファイル: LiftExporter.cs プロジェクト: bbriggs/wesay
		private void WriteFlags(IAnnotatable thing)
		{
			if (thing.IsStarred)
			{
				Writer.WriteStartElement("annotation");
				Writer.WriteAttributeString("name", "flag");
				Writer.WriteAttributeString("value", "1");
				Writer.WriteEndElement();
			}
		}
コード例 #30
0
 public static IEnumerable <PostgresExtension> GetPostgresExtensions([NotNull] IAnnotatable annotatable)
 => Check.NotNull(annotatable, nameof(annotatable))
 .GetAnnotations()
 .Where(a => a.Name.StartsWith(NpgsqlAnnotationNames.PostgresExtensionPrefix, StringComparison.Ordinal))
 .Select(a => new PostgresExtension(annotatable, a.Name));
コード例 #31
0
        protected override void ColumnDefinition(
            string schema,
            string table,
            string name,
            Type clrType,
            string type,
            bool? unicode,
            int? maxLength,
            bool rowVersion,
            bool nullable,
            object defaultValue,
            string defaultValueSql,
            string computedColumnSql,
            IAnnotatable annotatable,
            IModel model,
            MigrationCommandListBuilder builder)
        {
            var valueGenerationStrategy = annotatable[
                SqlServerFullAnnotationNames.Instance.ValueGenerationStrategy] as SqlServerValueGenerationStrategy?;

            ColumnDefinition(
                schema,
                table,
                name,
                clrType,
                type,
                unicode,
                maxLength,
                rowVersion,
                nullable,
                defaultValue,
                defaultValueSql,
                computedColumnSql,
                valueGenerationStrategy == SqlServerValueGenerationStrategy.IdentityColumn,
                annotatable,
                model,
                builder);
        }
		void AddOldAnnotationsToInitializer(AccessPath targetPath, IAnnotatable initializer)
		{
			if (targetPath != null) {
				if (accessPaths.ContainsKey(targetPath)) {
					foreach (var astNode in ReplacementNodeHelper.GetAllReplacementAnnotations(accessPaths[targetPath])) {
						initializer.AddAnnotation(astNode);
					}
				}
			}
		}
コード例 #33
0
        protected override void ColumnDefinition(
            string schema,
            string table,
            string name,
            Type clrType,
            string type,
            bool?unicode,
            int?maxLength,
            bool?fixedLength,
            bool rowVersion,
            bool nullable,
            object defaultValue,
            string defaultValueSql,
            string computedColumnSql,
            IAnnotatable annotatable,
            IModel model,
            MigrationCommandListBuilder builder)
        {
            Check.NotEmpty(name, nameof(name));
            Check.NotNull(annotatable, nameof(annotatable));
            Check.NotNull(clrType, nameof(clrType));
            Check.NotNull(builder, nameof(builder));

            if (type == null)
            {
                type = GetColumnType(schema, table, name, clrType, unicode, maxLength, fixedLength, rowVersion, model);
            }

            // User-defined type names are quoted if they contain uppercase letters. Other types are never quoted
            // since users sometimes prefer to write TEXT instead of text.
            if (_typeMappingSource.IsUserDefinedType(type))
            {
                type = _sqlGenerationHelper.DelimitIdentifier(type);
            }

            CheckForOldValueGenerationAnnotation(annotatable);
            var valueGenerationStrategy = annotatable[NpgsqlAnnotationNames.ValueGenerationStrategy] as NpgsqlValueGenerationStrategy?;

            if (valueGenerationStrategy == NpgsqlValueGenerationStrategy.SerialColumn)
            {
                switch (type)
                {
                case "int":
                case "int4":
                case "integer":
                    type = "serial";
                    break;

                case "bigint":
                case "int8":
                    type = "bigserial";
                    break;

                case "smallint":
                case "int2":
                    type = "smallserial";
                    break;
                }
            }

            base.ColumnDefinition(
                schema,
                table,
                name,
                clrType,
                type,
                unicode,
                maxLength,
                fixedLength,
                rowVersion,
                nullable,
                defaultValue,
                defaultValueSql,
                computedColumnSql,
                annotatable,
                model,
                builder);

            switch (valueGenerationStrategy)
            {
            case NpgsqlValueGenerationStrategy.IdentityAlwaysColumn:
                builder.Append(" GENERATED ALWAYS AS IDENTITY");
                break;

            case NpgsqlValueGenerationStrategy.IdentityByDefaultColumn:
                builder.Append(" GENERATED BY DEFAULT AS IDENTITY");
                break;
            }
        }
コード例 #34
0
 private static Type GetProviderType(IAnnotatable annotatable, Type valueType)
 => annotatable is IProperty property &&
コード例 #35
0
        protected override void ColumnDefinition(string schema, string table, string name, Type clrType, string type, bool?unicode, int?maxLength, bool?fixedLength, bool rowVersion, bool nullable, object defaultValue, string defaultValueSql, string computedColumnSql, IAnnotatable annotatable, IModel model, MigrationCommandListBuilder builder)
        {
            builder.Append(Dependencies.SqlGenerationHelper.DelimitIdentifier(name))
            .Append(" ")
            .Append(type ?? GetColumnType(schema, table, name, clrType, unicode, maxLength, fixedLength, rowVersion, model));

            var valueGenerationStrategy = annotatable[FbAnnotationNames.ValueGenerationStrategy] as FbValueGenerationStrategy?;

            if (valueGenerationStrategy == FbValueGenerationStrategy.IdentityColumn)
            {
                builder.Append(" GENERATED BY DEFAULT AS IDENTITY");
            }

            DefaultValue(defaultValue, defaultValueSql, builder);

            if (!nullable)
            {
                builder.Append(" NOT NULL");
            }
        }
        protected override void ColumnDefinition([CanBeNull] string schema, [NotNull] string table, [NotNull] string name, [NotNull] Type clrType, [CanBeNull] string type, [CanBeNull] bool?unicode, [CanBeNull] int?maxLength, bool rowVersion, bool nullable, [CanBeNull] object defaultValue, [CanBeNull] string defaultValueSql, [CanBeNull] string computedColumnSql, [NotNull] IAnnotatable annotatable, [CanBeNull] IModel model, [NotNull] MigrationCommandListBuilder builder)
        {
            Check.NotEmpty(name, nameof(name));
            Check.NotNull(annotatable, nameof(annotatable));
            Check.NotNull(clrType, nameof(clrType));
            Check.NotNull(builder, nameof(builder));

            if (type == null)
            {
                var property = FindProperty(model, schema, table, name);
                type = TypeMapper.FindMapping(property).StoreType;
            }

            var matchType = type;
            var matchLen  = "";
            var match     = TypeRe.Match(type);

            if (match.Success)
            {
                matchType = match.Groups[1].Value.ToLower();
                if (!string.IsNullOrWhiteSpace(match.Groups[2].Value))
                {
                    matchLen = match.Groups[2].Value;
                }
            }

            var autoIncrement                    = false;
            var generatedOnAddAnnotation         = annotatable[MySqlAnnotationNames.Prefix + MySqlAnnotationNames.ValueGeneratedOnAdd];
            var generatedOnAdd                   = generatedOnAddAnnotation != null && (bool)generatedOnAddAnnotation;
            var generatedOnAddOrUpdateAnnotation = annotatable[MySqlAnnotationNames.Prefix + MySqlAnnotationNames.ValueGeneratedOnAddOrUpdate];
            var generatedOnAddOrUpdate           = generatedOnAddOrUpdateAnnotation != null && (bool)generatedOnAddOrUpdateAnnotation;

            if (generatedOnAdd && string.IsNullOrWhiteSpace(defaultValueSql) && defaultValue == null)
            {
                switch (matchType)
                {
                case "tinyint":
                case "smallint":
                case "mediumint":
                case "int":
                case "bigint":
                    autoIncrement = true;
                    break;

                case "datetime":
                    if (_mySqlTypeMapper != null && !_mySqlTypeMapper.ConnectionSettings.SupportsDateTime6)
                    {
                        throw new InvalidOperationException(
                                  $"Error in {table}.{name}: DATETIME does not support values generated " +
                                  "on Add or Update in MySql <= 5.5, try explicitly setting the column type to TIMESTAMP");
                    }
                    goto case "timestamp";

                case "timestamp":
                    defaultValueSql = $"CURRENT_TIMESTAMP({matchLen})";
                    break;
                }
            }

            string onUpdateSql = null;

            if (generatedOnAddOrUpdate)
            {
                switch (matchType)
                {
                case "datetime":
                    if (_mySqlTypeMapper != null && !_mySqlTypeMapper.ConnectionSettings.SupportsDateTime6)
                    {
                        throw new InvalidOperationException($"Error in {table}.{name}: DATETIME does not support values generated " +
                                                            "on Add or Update in MySql <= 5.5, try explicitly setting the column type to TIMESTAMP");
                    }
                    goto case "timestamp";

                case "timestamp":
                    if (string.IsNullOrWhiteSpace(defaultValueSql) && defaultValue == null)
                    {
                        defaultValueSql = $"CURRENT_TIMESTAMP({matchLen})";
                    }
                    onUpdateSql = $"CURRENT_TIMESTAMP({matchLen})";
                    break;
                }
            }

            builder
            .Append(SqlGenerationHelper.DelimitIdentifier(name))
            .Append(" ")
            .Append(type ?? GetColumnType(schema, table, name, clrType, unicode, maxLength, rowVersion, model));

            if (!nullable)
            {
                builder.Append(" NOT NULL");
            }

            if (autoIncrement)
            {
                builder.Append(" AUTO_INCREMENT");
            }
            else
            {
                if (defaultValueSql != null)
                {
                    builder
                    .Append(" DEFAULT ")
                    .Append(defaultValueSql);
                }
                else if (defaultValue != null)
                {
                    builder
                    .Append(" DEFAULT ")
                    .Append(SqlGenerationHelper.GenerateLiteral(defaultValue));
                }
                if (onUpdateSql != null)
                {
                    builder
                    .Append(" ON UPDATE ")
                    .Append(onUpdateSql);
                }
            }
        }
コード例 #37
0
 public CockroachDbInterleaveInParent(IAnnotatable annotatable)
 {
     _annotatable = annotatable;
 }
コード例 #38
0
        protected override void ColumnDefinition(
            string schema,
            string table,
            string name,
            Type clrType,
            string type,
            bool?unicode,
            int?maxLength,
            bool?fixedLength,
            bool rowVersion,
            bool nullable,
            object defaultValue,
            string defaultValueSql,
            string computedColumnSql,
            IAnnotatable annotatable,
            IModel model,
            MigrationCommandListBuilder builder)
        {
            Check.NotEmpty(name, nameof(name));
            Check.NotNull(annotatable, nameof(annotatable));
            Check.NotNull(clrType, nameof(clrType));
            Check.NotNull(builder, nameof(builder));

            if (type == null)
            {
                type = GetColumnType(schema, table, name, clrType, unicode, maxLength, fixedLength, rowVersion, model);
            }

            CheckForOldValueGenerationAnnotation(annotatable);
            var valueGenerationStrategy = annotatable[NpgsqlAnnotationNames.ValueGenerationStrategy] as NpgsqlValueGenerationStrategy?;

            if (valueGenerationStrategy == NpgsqlValueGenerationStrategy.SerialColumn)
            {
                switch (type)
                {
                case "int":
                case "int4":
                case "integer":
                    type = "serial";
                    break;

                case "bigint":
                case "int8":
                    type = "bigserial";
                    break;

                case "smallint":
                case "int2":
                    type = "smallserial";
                    break;
                }
            }

            base.ColumnDefinition(
                schema,
                table,
                name,
                clrType,
                type,
                unicode,
                maxLength,
                fixedLength,
                rowVersion,
                nullable,
                defaultValue,
                defaultValueSql,
                computedColumnSql,
                annotatable,
                model,
                builder);

            switch (valueGenerationStrategy)
            {
            case NpgsqlValueGenerationStrategy.IdentityAlwaysColumn:
                builder.Append(" GENERATED ALWAYS AS IDENTITY");
                break;

            case NpgsqlValueGenerationStrategy.IdentityByDefaultColumn:
                builder.Append(" GENERATED BY DEFAULT AS IDENTITY");
                break;
            }
        }
 private bool IsMemoryOptimized([NotNull] IAnnotatable annotatable, [CanBeNull] IModel model, [CanBeNull] string schema, [NotNull] string tableName)
 => annotatable[SqlServerAnnotationNames.MemoryOptimized] as bool?
 ?? FindEntityTypes(model, schema, tableName)?.Any(t => t.SqlServer().IsMemoryOptimized) == true;