コード例 #1
0
        /// <summary>
        ///     Returns a value indicating whether the given column for a particular table-like store object can be set for the property.
        /// </summary>
        /// <param name="propertyBuilder"> The builder for the property being configured. </param>
        /// <param name="name"> The name of the column. </param>
        /// <param name="storeObject"> The identifier of the store object. </param>
        /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
        /// <returns> <see langword="true" /> if the property can be mapped to the given column. </returns>
        public static bool CanSetColumnName(
            [NotNull] this IConventionPropertyBuilder propertyBuilder,
            [CanBeNull] string name,
            StoreObjectIdentifier storeObject,
            bool fromDataAnnotation = false)
        {
            var overrides = RelationalPropertyOverrides.Find(propertyBuilder.Metadata, storeObject);

            return(overrides == null ||
                   (fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention)
                   .Overrides(overrides.GetColumnNameConfigurationSource()) ||
                   overrides.ColumnName == name);
        }
コード例 #2
0
        /// <summary>
        ///     Configures the default value expression for the column that the property maps to when targeting a relational database.
        /// </summary>
        /// <param name="propertyBuilder"> The builder for the property being configured. </param>
        /// <param name="sql"> The SQL expression for the default value of the column. </param>
        /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
        /// <returns>
        ///     The same builder instance if the configuration was applied,
        ///     <see langword="null" /> otherwise.
        /// </returns>
        public static IConventionPropertyBuilder HasDefaultValueSql(
            [NotNull] this IConventionPropertyBuilder propertyBuilder,
            [CanBeNull] string sql,
            bool fromDataAnnotation = false)
        {
            if (!propertyBuilder.CanSetDefaultValueSql(sql, fromDataAnnotation))
            {
                return(null);
            }

            propertyBuilder.Metadata.SetDefaultValueSql(sql, fromDataAnnotation);
            return(propertyBuilder);
        }
コード例 #3
0
        /// <summary>
        ///     Configures the property as capable of storing only fixed-length data, such as strings.
        /// </summary>
        /// <param name="propertyBuilder"> The builder for the property being configured. </param>
        /// <param name="fixedLength"> A value indicating whether the property is constrained to fixed length values. </param>
        /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
        /// <returns>
        ///     The same builder instance if the configuration was applied,
        ///     <see langword="null" /> otherwise.
        /// </returns>
        public static IConventionPropertyBuilder IsFixedLength(
            [NotNull] this IConventionPropertyBuilder propertyBuilder,
            bool?fixedLength,
            bool fromDataAnnotation = false)
        {
            if (!propertyBuilder.CanSetIsFixedLength(fixedLength, fromDataAnnotation))
            {
                return(null);
            }

            propertyBuilder.Metadata.SetIsFixedLength(fixedLength, fromDataAnnotation);
            return(propertyBuilder);
        }
コード例 #4
0
        /// <summary>
        ///     Configures the data type of the column that the property maps to when targeting a relational database.
        ///     This should be the complete type name, including precision, scale, length, etc.
        /// </summary>
        /// <param name="propertyBuilder"> The builder for the property being configured. </param>
        /// <param name="typeName"> The name of the data type of the column. </param>
        /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
        /// <returns>
        ///     The same builder instance if the configuration was applied,
        ///     <see langword="null" /> otherwise.
        /// </returns>
        public static IConventionPropertyBuilder HasColumnType(
            [NotNull] this IConventionPropertyBuilder propertyBuilder,
            [CanBeNull] string typeName,
            bool fromDataAnnotation = false)
        {
            if (!propertyBuilder.CanSetColumnType(typeName, fromDataAnnotation))
            {
                return(null);
            }

            propertyBuilder.Metadata.SetColumnType(typeName, fromDataAnnotation);
            return(propertyBuilder);
        }
コード例 #5
0
        /// <summary>
        ///     Returns a value indicating whether the given name and schema can be set for the hi-lo sequence.
        /// </summary>
        /// <param name="propertyBuilder"> The builder for the property being configured. </param>
        /// <param name="name"> The name of the sequence. </param>
        /// <param name="schema">The schema of the sequence. </param>
        /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
        /// <returns> <see langword="true" /> if the given name and schema can be set for the hi-lo sequence. </returns>
        public static bool CanSetHiLoSequence(
            [NotNull] this IConventionPropertyBuilder propertyBuilder,
            [CanBeNull] string name,
            [CanBeNull] string schema,
            bool fromDataAnnotation = false)
        {
            Check.NotNull(propertyBuilder, nameof(propertyBuilder));
            Check.NullButNotEmpty(name, nameof(name));
            Check.NullButNotEmpty(schema, nameof(schema));

            return(propertyBuilder.CanSetAnnotation(SqlServerAnnotationNames.HiLoSequenceName, name, fromDataAnnotation) &&
                   propertyBuilder.CanSetAnnotation(SqlServerAnnotationNames.HiLoSequenceSchema, schema, fromDataAnnotation));
        }
コード例 #6
0
        /// <summary>
        ///     Configures the SRID of the column that the property maps to when targeting SQLite.
        /// </summary>
        /// <param name="propertyBuilder"> The builder for the property being configured. </param>
        /// <param name="srid"> The SRID. </param>
        /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
        /// <returns>
        ///     The same builder instance if the configuration was applied,
        ///     <see langword="null" /> otherwise.
        /// </returns>
        public static IConventionPropertyBuilder?HasSrid(
            this IConventionPropertyBuilder propertyBuilder,
            int?srid,
            bool fromDataAnnotation = false)
        {
            if (propertyBuilder.CanSetSrid(srid, fromDataAnnotation))
            {
                propertyBuilder.Metadata.SetSrid(srid, fromDataAnnotation);

                return(propertyBuilder);
            }

            return(null);
        }
コード例 #7
0
        /// <summary>
        ///     Returns a value indicating whether the given column in a particular view can be set for the property.
        /// </summary>
        /// <param name="propertyBuilder"> The builder for the property being configured. </param>
        /// <param name="name"> The name of the column. </param>
        /// <param name="viewName"> The view name. </param>
        /// <param name="schema"> The view schema. </param>
        /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
        /// <returns> <see langword="true" /> if the property can be mapped to the given column. </returns>
        public static bool CanSetViewColumnName(
            [NotNull] this IConventionPropertyBuilder propertyBuilder,
            [CanBeNull] string name,
            [NotNull] string viewName,
            [CanBeNull] string schema,
            bool fromDataAnnotation = false)
        {
            var overrides = RelationalPropertyOverrides.Find(propertyBuilder.Metadata, viewName, schema);

            return(overrides == null ||
                   (fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention)
                   .Overrides(overrides.GetViewColumnNameConfigurationSource()) ||
                   overrides.ViewColumnName == name);
        }
コード例 #8
0
        /// <summary>
        ///     <para>
        ///         Configures the property name that the property is mapped to when targeting Azure Cosmos.
        ///     </para>
        ///     <para>
        ///         If an empty string is supplied then the property will not be persisted.
        ///     </para>
        /// </summary>
        /// <param name="propertyBuilder"> The builder for the property being configured. </param>
        /// <param name="name"> The name of the property. </param>
        /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
        /// <returns>
        ///     The same builder instance if the configuration was applied,
        ///     <c>null</c> otherwise.
        /// </returns>
        public static IConventionPropertyBuilder ToJsonProperty(
            [NotNull] this IConventionPropertyBuilder propertyBuilder,
            [CanBeNull] string name,
            bool fromDataAnnotation = false)
        {
            if (!propertyBuilder.CanSetJsonProperty(name, fromDataAnnotation))
            {
                return(null);
            }

            propertyBuilder.Metadata.SetJsonPropertyName(name, fromDataAnnotation);

            return(propertyBuilder);
        }
コード例 #9
0
        /// <summary>
        /// <para>
        /// Configures the property to use the PostgreSQL IDENTITY feature to generate values for new entities,
        /// when targeting PostgreSQL. This method sets the property to be <see cref="ValueGenerated.OnAdd" />.
        /// Values for this property will be generated as identity by default, but the application will be able
        /// to override this behavior by providing a value.
        /// </para>
        /// <para>
        /// This is the default behavior when targeting PostgreSQL. Available only starting PostgreSQL 10.
        /// </para>
        /// </summary>
        /// <param name="propertyBuilder"> The builder for the property being configured.</param>
        /// <returns>The same builder instance so that multiple calls can be chained.</returns>
        public static IConventionPropertyBuilder UseIdentityByDefaultColumn([NotNull] this IConventionPropertyBuilder propertyBuilder)
        {
            if (propertyBuilder.CanSetValueGenerationStrategy(NpgsqlValueGenerationStrategy.IdentityByDefaultColumn))
            {
                var property = propertyBuilder.Metadata;
                property.SetValueGenerationStrategy(NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
                property.SetHiLoSequenceName(null);
                property.SetHiLoSequenceSchema(null);

                return(propertyBuilder);
            }

            return(null);
        }
コード例 #10
0
        /// <summary>
        ///     Configures whether the property's column is created as sparse when targeting SQL Server.
        /// </summary>
        /// <remarks>
        ///     See <see href="https://aka.ms/efcore-docs-modeling">Modeling entity types and relationships</see>, and
        ///     <see href="https://aka.ms/efcore-docs-sqlserver">Accessing SQL Server and SQL Azure databases with EF Core</see>
        ///     for more information.
        /// </remarks>
        /// <param name="propertyBuilder">The builder for the property being configured.</param>
        /// <param name="sparse">A value indicating whether the property's column is created as sparse.</param>
        /// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
        /// <returns>The same builder instance if the configuration was applied, <see langword="null" /> otherwise.</returns>
        /// <remarks> See https://docs.microsoft.com/sql/relational-databases/tables/use-sparse-columns. </remarks>
        public static IConventionPropertyBuilder?IsSparse(
            this IConventionPropertyBuilder propertyBuilder,
            bool?sparse,
            bool fromDataAnnotation = false)
        {
            if (propertyBuilder.CanSetIsSparse(sparse, fromDataAnnotation))
            {
                propertyBuilder.Metadata.SetIsSparse(sparse, fromDataAnnotation);

                return(propertyBuilder);
            }

            return(null);
        }
コード例 #11
0
        /// <summary>
        ///     Configures the property to use the given collation. The database column will be be created with the given
        ///     collation, and it will be used implicitly in all collation-sensitive operations.
        /// </summary>
        /// <param name="propertyBuilder"> The builder for the property being configured. </param>
        /// <param name="collation"> The collation. </param>
        /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
        /// <returns>
        ///     The same builder instance if the configuration was applied,
        ///     <see langword="null" /> otherwise.
        /// </returns>
        public static IConventionPropertyBuilder UseCollation(
            [NotNull] this IConventionPropertyBuilder propertyBuilder,
            [CanBeNull] string collation,
            bool fromDataAnnotation = false)
        {
            if (propertyBuilder.CanSetCollation(collation, fromDataAnnotation))
            {
                propertyBuilder.Metadata.SetCollation(collation, fromDataAnnotation);

                return(propertyBuilder);
            }

            return(null);
        }
コード例 #12
0
        private void Process(IConventionPropertyBuilder propertyBuilder, IConventionContext context)
        {
            var property = propertyBuilder.Metadata;

            if (property.IsImplicitlyCreated() &&
                ConfigurationSource.Convention.Overrides(property.GetConfigurationSource()))
            {
                return;
            }

            var entityType = propertyBuilder.Metadata.DeclaringEntityType;

            Process(entityType, context);
        }
コード例 #13
0
        /// <summary>
        ///     Configures the dimension of the column that the property maps to when targeting SQLite.
        /// </summary>
        /// <param name="propertyBuilder"> The builder for the property being configured. </param>
        /// <param name="dimension"> The dimension. </param>
        /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
        /// <returns>
        ///     The same builder instance if the configuration was applied,
        ///     <c>null</c> otherwise.
        /// </returns>
        public static IConventionPropertyBuilder ForSqliteHasDimension(
            [NotNull] this IConventionPropertyBuilder propertyBuilder,
            string dimension,
            bool fromDataAnnotation = false)
        {
            if (propertyBuilder.ForSqliteCanSetDimension(dimension, fromDataAnnotation))
            {
                propertyBuilder.Metadata.SetSqliteDimension(dimension, fromDataAnnotation);

                return(propertyBuilder);
            }

            return(null);
        }
コード例 #14
0
    /// <summary>
    /// Sets the compression method for the column.
    /// </summary>
    /// <remarks>This feature was introduced in PostgreSQL 14.</remarks>
    /// <param name="propertyBuilder">The builder for the property being configured.</param>
    /// <param name="compressionMethod">The compression method.</param>
    /// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
    /// <returns>A builder to further configure the property.</returns>
    public static IConventionPropertyBuilder?UseCompressionMethod(
        this IConventionPropertyBuilder propertyBuilder,
        string?compressionMethod,
        bool fromDataAnnotation = false)
    {
        if (propertyBuilder.CanSetCompressionMethod(compressionMethod, fromDataAnnotation))
        {
            propertyBuilder.Metadata.SetCompressionMethod(compressionMethod, fromDataAnnotation);

            return(propertyBuilder);
        }

        return(null);
    }
        /// <summary>
        ///     Configures the dimension of the column that the property maps to when targeting SQLite.
        /// </summary>
        /// <param name="propertyBuilder"> The builder for the property being configured. </param>
        /// <param name="dimension"> The dimension. </param>
        /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
        /// <returns>
        ///     The same builder instance if the configuration was applied,
        ///     <c>null</c> otherwise.
        /// </returns>
        public static IConventionPropertyBuilder HasGeometricDimension(
            [NotNull] this IConventionPropertyBuilder propertyBuilder,
            [CanBeNull] string dimension,
            bool fromDataAnnotation = false)
        {
            if (propertyBuilder.CanSetGeometricDimension(dimension, fromDataAnnotation))
            {
                propertyBuilder.Metadata.SetGeometricDimension(dimension, fromDataAnnotation);

                return(propertyBuilder);
            }

            return(null);
        }
コード例 #16
0
        /// <summary>
        ///     Configures the SRID of the column that the property maps to when targeting SQLite.
        /// </summary>
        /// <param name="propertyBuilder"> The builder for the property being configured. </param>
        /// <param name="srid"> The SRID. </param>
        /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
        /// <returns>
        ///     The same builder instance if the configuration was applied,
        ///     <c>null</c> otherwise.
        /// </returns>
        public static IConventionPropertyBuilder ForSqliteHasSrid(
            [NotNull] this IConventionPropertyBuilder propertyBuilder,
            int?srid,
            bool fromDataAnnotation = false)
        {
            if (propertyBuilder.ForSqliteCanSetSrid(srid, fromDataAnnotation))
            {
                propertyBuilder.Metadata.SetSqliteSrid(srid, fromDataAnnotation);

                return(propertyBuilder);
            }

            return(null);
        }
コード例 #17
0
        /// <summary>
        ///     Configures the column that the property maps to in a particular table-like store object.
        /// </summary>
        /// <param name="propertyBuilder"> The builder for the property being configured. </param>
        /// <param name="name"> The name of the column. </param>
        /// <param name="storeObject"> The identifier of the store object. </param>
        /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
        /// <returns>
        ///     The same builder instance if the configuration was applied,
        ///     <see langword="null" /> otherwise.
        /// </returns>
        public static IConventionPropertyBuilder HasColumnName(
            [NotNull] this IConventionPropertyBuilder propertyBuilder,
            [CanBeNull] string name,
            StoreObjectIdentifier storeObject,
            bool fromDataAnnotation = false)
        {
            if (!propertyBuilder.CanSetColumnName(name, storeObject, fromDataAnnotation))
            {
                return(null);
            }

            propertyBuilder.Metadata.SetColumnName(name, storeObject, fromDataAnnotation);
            return(propertyBuilder);
        }
コード例 #18
0
        /// <summary>
        ///     Called after an annotation is changed on a property.
        /// </summary>
        /// <param name="propertyBuilder"> The builder for the property. </param>
        /// <param name="name"> The annotation name. </param>
        /// <param name="annotation"> The new annotation. </param>
        /// <param name="oldAnnotation"> The old annotation.  </param>
        /// <param name="context"> Additional information associated with convention execution. </param>
        public virtual void ProcessPropertyAnnotationChanged(
            IConventionPropertyBuilder propertyBuilder,
            string name,
            IConventionAnnotation annotation,
            IConventionAnnotation oldAnnotation,
            IConventionContext <IConventionAnnotation> context)
        {
            if (annotation == null ||
                oldAnnotation?.Value != null)
            {
                return;
            }

            var configurationSource = annotation.GetConfigurationSource();
            var fromDataAnnotation  = configurationSource != ConfigurationSource.Convention;

            switch (name)
            {
            case RelationalAnnotationNames.DefaultValue:
                if ((propertyBuilder.HasDefaultValueSql(null, fromDataAnnotation) == null
                     | propertyBuilder.HasComputedColumnSql(null, fromDataAnnotation) == null) &&
                    propertyBuilder.HasDefaultValue(null, fromDataAnnotation) != null)
                {
                    context.StopProcessing();
                }

                break;

            case RelationalAnnotationNames.DefaultValueSql:
                if ((propertyBuilder.HasDefaultValue(null, fromDataAnnotation) == null
                     | propertyBuilder.HasComputedColumnSql(null, fromDataAnnotation) == null) &&
                    propertyBuilder.HasDefaultValueSql(null, fromDataAnnotation) != null)
                {
                    context.StopProcessing();
                }

                break;

            case RelationalAnnotationNames.ComputedColumnSql:
                if ((propertyBuilder.HasDefaultValue(null, fromDataAnnotation) == null
                     | propertyBuilder.HasDefaultValueSql(null, fromDataAnnotation) == null) &&
                    propertyBuilder.HasComputedColumnSql(null, fromDataAnnotation) != null)
                {
                    context.StopProcessing();
                }

                break;
            }
        }
コード例 #19
0
 /// <summary>
 ///     Called after an annotation is changed on a property.
 /// </summary>
 /// <param name="propertyBuilder"> The builder for the property. </param>
 /// <param name="name"> The annotation name. </param>
 /// <param name="annotation"> The new annotation. </param>
 /// <param name="oldAnnotation"> The old annotation.  </param>
 /// <param name="context"> Additional information associated with convention execution. </param>
 public virtual void ProcessPropertyAnnotationChanged(
     IConventionPropertyBuilder propertyBuilder,
     string name,
     IConventionAnnotation annotation,
     IConventionAnnotation oldAnnotation,
     IConventionContext <IConventionAnnotation> context)
 {
     if (name == RelationalAnnotationNames.ColumnName)
     {
         foreach (var index in propertyBuilder.Metadata.GetContainingIndexes())
         {
             SetIndexFilter(index.Builder, columnNameChanged: true);
         }
     }
 }
コード例 #20
0
        protected override void ProcessPropertyAdded(
            IConventionPropertyBuilder propertyBuilder,
            DatabaseGeneratedAttribute attribute,
            MemberInfo clrMember,
            IConventionContext context)
        {
            var valueGenerated =
                attribute.DatabaseGeneratedOption == DatabaseGeneratedOption.Identity
                    ? ValueGenerated.OnAdd
                    : attribute.DatabaseGeneratedOption == DatabaseGeneratedOption.Computed
                        ? ValueGenerated.OnAddOrUpdate
                        : ValueGenerated.Never;

            propertyBuilder.ValueGenerated(valueGenerated, fromDataAnnotation: true);
        }
コード例 #21
0
 public static IConventionPropertyBuilder HasValueGenerationStrategy(this IConventionPropertyBuilder propertyBuilder, FbValueGenerationStrategy?valueGenerationStrategy, bool fromDataAnnotation = false)
 {
     if (propertyBuilder.CanSetAnnotation(FbAnnotationNames.ValueGenerationStrategy, valueGenerationStrategy, fromDataAnnotation))
     {
         propertyBuilder.Metadata.SetValueGenerationStrategy(valueGenerationStrategy, fromDataAnnotation);
         if (valueGenerationStrategy != FbValueGenerationStrategy.IdentityColumn)
         {
         }
         if (valueGenerationStrategy != FbValueGenerationStrategy.SequenceTrigger)
         {
         }
         return(propertyBuilder);
     }
     return(null);
 }
コード例 #22
0
        /// <summary>
        ///     Called after a property is added to the entity type.
        /// </summary>
        /// <param name="propertyBuilder"> The builder for the property. </param>
        /// <param name="context"> Additional information associated with convention execution. </param>
        public virtual void ProcessPropertyAdded(
            IConventionPropertyBuilder propertyBuilder,
            IConventionContext <IConventionPropertyBuilder> context)
        {
            Check.NotNull(propertyBuilder, nameof(propertyBuilder));

            var memberInfo = propertyBuilder.Metadata.GetIdentifyingMemberInfo();

            if (memberInfo == null)
            {
                return;
            }

            Process(propertyBuilder, memberInfo, (IReadableConventionContext)context);
        }
コード例 #23
0
        /// <summary>
        ///     Configures the column that the property maps to in a particular table when targeting a relational database.
        /// </summary>
        /// <param name="propertyBuilder"> The builder for the property being configured. </param>
        /// <param name="name"> The name of the column. </param>
        /// <param name="tableName"> The table name. </param>
        /// <param name="schema"> The table schema. </param>
        /// <param name="fromDataAnnotation"> Indicates whether the configuration was specified using a data annotation. </param>
        /// <returns>
        ///     The same builder instance if the configuration was applied,
        ///     <see langword="null" /> otherwise.
        /// </returns>
        public static IConventionPropertyBuilder HasColumnName(
            [NotNull] this IConventionPropertyBuilder propertyBuilder,
            [CanBeNull] string name,
            [NotNull] string tableName,
            [CanBeNull] string schema,
            bool fromDataAnnotation = false)
        {
            if (!propertyBuilder.CanSetColumnName(name, tableName, schema, fromDataAnnotation))
            {
                return(null);
            }

            propertyBuilder.Metadata.SetColumnName(name, tableName, schema, fromDataAnnotation);
            return(propertyBuilder);
        }
        /// <summary>
        ///     Called after an annotation is changed on a property.
        /// </summary>
        /// <param name="propertyBuilder"> The builder for the property. </param>
        /// <param name="name"> The annotation name. </param>
        /// <param name="annotation"> The new annotation. </param>
        /// <param name="oldAnnotation"> The old annotation.  </param>
        /// <param name="context"> Additional information associated with convention execution. </param>
        public override void ProcessPropertyAnnotationChanged(
            IConventionPropertyBuilder propertyBuilder,
            string name,
            IConventionAnnotation annotation,
            IConventionAnnotation oldAnnotation,
            IConventionContext <IConventionAnnotation> context)
        {
            if (name == SqlServerAnnotationNames.ValueGenerationStrategy)
            {
                propertyBuilder.ValueGenerated(GetValueGenerated(propertyBuilder.Metadata));
                return;
            }

            base.ProcessPropertyAnnotationChanged(propertyBuilder, name, annotation, oldAnnotation, context);
        }
        /// <inheritdoc />
        protected override void ProcessPropertyAdded(
            IConventionPropertyBuilder propertyBuilder,
            DatabaseGeneratedAttribute attribute,
            MemberInfo clrMember,
            IConventionContext context)
        {
            if (attribute.DatabaseGeneratedOption == DatabaseGeneratedOption.Identity)
            {
                propertyBuilder.Metadata
                .DeclaringEntityType
                .MongoDb()
                .AssignIdOnInsert = true;
            }

            base.ProcessPropertyAdded(propertyBuilder, attribute, clrMember, context);
        }
コード例 #26
0
        /// <summary>
        ///     Called after a property is added to the entity type with an attribute on the associated CLR property or field.
        /// </summary>
        /// <param name="propertyBuilder"> The builder for the property. </param>
        /// <param name="attribute"> The attribute. </param>
        /// <param name="clrMember"> The member that has the attribute. </param>
        /// <param name="context"> Additional information associated with convention execution. </param>
        protected override void ProcessPropertyAdded(
            IConventionPropertyBuilder propertyBuilder,
            ColumnAttribute attribute,
            MemberInfo clrMember,
            IConventionContext context)
        {
            if (!string.IsNullOrWhiteSpace(attribute.Name))
            {
                propertyBuilder.HasColumnName(attribute.Name, fromDataAnnotation: true);
            }

            if (!string.IsNullOrWhiteSpace(attribute.TypeName))
            {
                propertyBuilder.HasColumnType(attribute.TypeName, fromDataAnnotation: true);
            }
        }
コード例 #27
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public virtual IConventionAnnotation OnPropertyAnnotationChanged(
            [NotNull] IConventionPropertyBuilder propertyBuilder,
            [NotNull] string name,
            [CanBeNull] IConventionAnnotation annotation,
            [CanBeNull] IConventionAnnotation oldAnnotation)
        {
            if (CoreAnnotationNames.AllNames.Contains(name))
            {
                return(annotation);
            }

            return(_scope.OnPropertyAnnotationChanged(
                       propertyBuilder,
                       name,
                       annotation,
                       oldAnnotation));
        }
コード例 #28
0
        /// <summary>
        /// Returns a value indicating whether the property can be configured as a full-text search tsvector column.
        /// </summary>
        /// <param name="propertyBuilder">The builder for the property being configured.</param>
        /// <param name="config">
        /// <para>
        /// The text search configuration for this generated tsvector property, or <c>null</c> if this is not a
        /// generated tsvector property.
        /// </para>
        /// <para>
        /// See https://www.postgresql.org/docs/current/textsearch-controls.html for more information.
        /// </para>
        /// </param>
        /// <param name="includedPropertyNames">An array of property names to be included in the tsvector.</param>
        /// <param name="fromDataAnnotation">Indicates whether the configuration was specified using a data annotation.</param>
        /// <returns><c>true</c> if the property can be configured as a full-text search tsvector column.</returns>
        public static bool CanSetIsGeneratedTsVectorColumn(
            [NotNull] this IConventionPropertyBuilder propertyBuilder,
            [CanBeNull] string config,
            [CanBeNull] IReadOnlyList <string> includedPropertyNames,
            bool fromDataAnnotation = false)
        {
            Check.NotNull(propertyBuilder, nameof(propertyBuilder));

            return((fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention)
                   .Overrides(propertyBuilder.Metadata.GetTsVectorConfigConfigurationSource()) &&
                   (fromDataAnnotation ? ConfigurationSource.DataAnnotation : ConfigurationSource.Convention)
                   .Overrides(propertyBuilder.Metadata.GetTsVectorPropertiesConfigurationSource())
                   ||
                   config == propertyBuilder.Metadata.GetTsVectorConfig() &&
                   StructuralComparisons.StructuralEqualityComparer.Equals(
                       includedPropertyNames, propertyBuilder.Metadata.GetTsVectorProperties()));
        }
コード例 #29
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public virtual IConventionAnnotation?OnPropertyAnnotationChanged(
            IConventionPropertyBuilder propertyBuilder,
            string name,
            IConventionAnnotation?annotation,
            IConventionAnnotation?oldAnnotation)
        {
            if (CoreAnnotationNames.AllNames.Contains(name))
            {
                return(annotation);
            }

            return(_scope.OnPropertyAnnotationChanged(
                       propertyBuilder,
                       name,
                       annotation,
                       oldAnnotation));
        }
コード例 #30
0
 /// <summary>
 ///     Called after an annotation is changed on a property.
 /// </summary>
 /// <param name="propertyBuilder">The builder for the property.</param>
 /// <param name="name">The annotation name.</param>
 /// <param name="annotation">The new annotation.</param>
 /// <param name="oldAnnotation">The old annotation.</param>
 /// <param name="context">Additional information associated with convention execution.</param>
 public virtual void ProcessPropertyAnnotationChanged(
     IConventionPropertyBuilder propertyBuilder,
     string name,
     IConventionAnnotation? annotation,
     IConventionAnnotation? oldAnnotation,
     IConventionContext<IConventionAnnotation> context)
 {
     var property = propertyBuilder.Metadata;
     switch (name)
     {
         case RelationalAnnotationNames.DefaultValue:
         case RelationalAnnotationNames.DefaultValueSql:
         case RelationalAnnotationNames.ComputedColumnSql:
             propertyBuilder.ValueGenerated(GetValueGenerated(property));
             break;
     }
 }