public override Annotation Apply(InternalPropertyBuilder propertyBuilder, string name, Annotation annotation, Annotation oldAnnotation)
        {
            if (annotation == null ||
                oldAnnotation?.Value != null)
            {
                return(annotation);
            }

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

            switch (name)
            {
            case RelationalAnnotationNames.DefaultValue:
                if (propertyBuilder.ForSqlServerHasValueGenerationStrategy(null, fromDataAnnotation) == null &&
                    propertyBuilder.HasDefaultValue(null, fromDataAnnotation) != null)
                {
                    return(null);
                }

                break;

            case RelationalAnnotationNames.DefaultValueSql:
                if (propertyBuilder.ForSqlServerHasValueGenerationStrategy(null, fromDataAnnotation) == null &&
                    propertyBuilder.HasDefaultValueSql(null, fromDataAnnotation) != null)
                {
                    return(null);
                }

                break;

            case RelationalAnnotationNames.ComputedColumnSql:
                if (propertyBuilder.ForSqlServerHasValueGenerationStrategy(null, fromDataAnnotation) == null &&
                    propertyBuilder.HasComputedColumnSql(null, fromDataAnnotation) != null)
                {
                    return(null);
                }

                break;

            case SqlServerAnnotationNames.ValueGenerationStrategy:
                if (propertyBuilder.HasDefaultValue(null, fromDataAnnotation) == null
                    | propertyBuilder.HasDefaultValueSql(null, fromDataAnnotation) == null
                    | propertyBuilder.HasComputedColumnSql(null, fromDataAnnotation) == null)
                {
                    return(propertyBuilder.ForSqlServerHasValueGenerationStrategy(null, fromDataAnnotation) == null
                            ? annotation
                            : null);
                }

                break;
            }

            return(base.Apply(propertyBuilder, name, annotation, oldAnnotation));
        }
Example #2
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 Annotation Apply(
            InternalPropertyBuilder propertyBuilder,
            string name,
            Annotation annotation,
            Annotation oldAnnotation)
        {
            if (annotation == null ||
                oldAnnotation?.Value != null)
            {
                return(annotation);
            }

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

            switch (name)
            {
            case RelationalAnnotationNames.DefaultValue:
                if (propertyBuilder.HasDefaultValueSql(null, fromDataAnnotation) == null
                    | propertyBuilder.HasComputedColumnSql(null, fromDataAnnotation) == null)
                {
                    return(propertyBuilder.HasDefaultValue(null, fromDataAnnotation) == null
                            ? annotation
                            : null);
                }

                break;

            case RelationalAnnotationNames.DefaultValueSql:
                if (propertyBuilder.HasDefaultValue(null, fromDataAnnotation) == null
                    | propertyBuilder.HasComputedColumnSql(null, fromDataAnnotation) == null)
                {
                    return(propertyBuilder.HasDefaultValueSql(null, fromDataAnnotation) == null
                            ? annotation
                            : null);
                }

                break;

            case RelationalAnnotationNames.ComputedColumnSql:
                if (propertyBuilder.HasDefaultValue(null, fromDataAnnotation) == null
                    | propertyBuilder.HasDefaultValueSql(null, fromDataAnnotation) == null)
                {
                    return(propertyBuilder.HasComputedColumnSql(null, fromDataAnnotation) == null
                            ? annotation
                            : null);
                }

                break;
            }

            return(annotation);
        }