Exemplo n.º 1
0
        protected override void Validate(IConventionProperty property)
        {
            if (property.GetValueGenerationStrategyConfigurationSource() != null &&
                property.GetValueGenerationStrategy() != JetValueGenerationStrategy.None)
            {
                if (property.GetDefaultValue() != null)
                {
                    throw new InvalidOperationException(
                              RelationalStrings.ConflictingColumnServerGeneration(
                                  "JetValueGenerationStrategy", property.Name, "DefaultValue"));
                }

                if (property.GetDefaultValueSql() != null)
                {
                    throw new InvalidOperationException(
                              RelationalStrings.ConflictingColumnServerGeneration(
                                  "JetValueGenerationStrategy", property.Name, "DefaultValueSql"));
                }

                if (property.GetComputedColumnSql() != null)
                {
                    throw new InvalidOperationException(
                              RelationalStrings.ConflictingColumnServerGeneration(
                                  "JetValueGenerationStrategy", property.Name, "ComputedColumnSql"));
                }
            }

            base.Validate(property);
        }
        /// <summary>
        ///     Throws if there is conflicting store generation configuration for this property.
        /// </summary>
        /// <param name="property"> The property to check. </param>
        protected virtual void Validate([NotNull] IConventionProperty property)
        {
            if (property.GetDefaultValue() != null)
            {
                if (property.GetDefaultValueSql() != null)
                {
                    throw new InvalidOperationException(
                              RelationalStrings.ConflictingColumnServerGeneration("DefaultValue", property.Name, "DefaultValueSql"));
                }

                if (property.GetComputedColumnSql() != null)
                {
                    throw new InvalidOperationException(
                              RelationalStrings.ConflictingColumnServerGeneration("DefaultValue", property.Name, "ComputedColumnSql"));
                }
            }
            else if (property.GetDefaultValueSql() != null)
            {
                if (property.GetComputedColumnSql() != null)
                {
                    throw new InvalidOperationException(
                              RelationalStrings.ConflictingColumnServerGeneration("DefaultValueSql", property.Name, "ComputedColumnSql"));
                }
            }
        }
 /// <summary>
 /// 是否能设置值生成策略
 /// </summary>
 /// <param name="value">值生成策略</param>
 /// <returns></returns>
 protected virtual bool CanSetValueGenerationStrategy(OracleValueGenerationStrategy?value)
 {
     if (GetOracleValueGenerationStrategy(fallbackToModel: false) == value)
     {
         return(true);
     }
     if (!Annotations.CanSetAnnotation(OracleAnnotationNames.ValueGenerationStrategy, value))
     {
         return(false);
     }
     if (ShouldThrowOnConflict)
     {
         if (GetDefaultValue(fallback: false) != null)
         {
             throw new InvalidOperationException(RelationalStrings.ConflictingColumnServerGeneration(nameof(ValueGenerationStrategy), Property.Name, nameof(DefaultValue)));
         }
         if (GetDefaultValueSql(fallback: false) != null)
         {
             throw new InvalidOperationException(RelationalStrings.ConflictingColumnServerGeneration(nameof(ValueGenerationStrategy), Property.Name, nameof(DefaultValueSql)));
         }
         if (GetComputedColumnSql(fallback: false) != null)
         {
             throw new InvalidOperationException(RelationalStrings.ConflictingColumnServerGeneration(nameof(ValueGenerationStrategy), Property.Name, nameof(ComputedColumnSql)));
         }
     }
     else if (value.HasValue && (!CanSetDefaultValue(null) || !CanSetDefaultValueSql(null) || !CanSetComputedColumnSql(null)))
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 4
0
        public void Metadata_throws_when_setting_conflicting_serverGenerated_values(string firstConfiguration, string secondConfiguration)
        {
            var modelBuilder = CreateConventionalModelBuilder();

            var propertyBuilder = modelBuilder.Entity <Dog>().Property <int?>("NullableInt");

            ConfigureProperty(propertyBuilder.Metadata, firstConfiguration, "1");
            ConfigureProperty(propertyBuilder.Metadata, secondConfiguration, "2");

            VerifyError(RelationalStrings.ConflictingColumnServerGeneration(firstConfiguration, "NullableInt", secondConfiguration), modelBuilder.Model);
        }
Exemplo n.º 5
0
        public void Metadata_throws_when_setting_conflicting_serverGenerated_values(string firstConfiguration, string secondConfiguration)
        {
            var modelBuilder = GetModelBuilder();

            var propertyBuilder = modelBuilder
                                  .Entity <Customer>()
                                  .Property(e => e.NullableInt);

            ConfigureProperty(propertyBuilder.Metadata, firstConfiguration, "1");

            Assert.Equal(RelationalStrings.ConflictingColumnServerGeneration(secondConfiguration, nameof(Customer.NullableInt), firstConfiguration),
                         Assert.Throws <InvalidOperationException>(() =>
                                                                   ConfigureProperty(propertyBuilder.Metadata, secondConfiguration, "2")).Message);
        }
 /// <summary>
 /// 是否能设置计算列SQL
 /// </summary>
 /// <param name="value">值</param>
 /// <returns></returns>
 protected override bool CanSetComputedColumnSql(string value)
 {
     if (ShouldThrowOnConflict)
     {
         if (ValueGenerationStrategy.HasValue)
         {
             throw new InvalidOperationException(RelationalStrings.ConflictingColumnServerGeneration(nameof(ComputedColumnSql), Property.Name, nameof(ValueGenerationStrategy)));
         }
     }
     else if (value != null && !CanSetValueGenerationStrategy(null))
     {
         return(false);
     }
     return(base.CanSetComputedColumnSql(value));
 }
Exemplo n.º 7
0
        protected virtual bool CanSetDefaultValue([CanBeNull] object value)
        {
            if (GetDefaultValue(false) == value)
            {
                return(true);
            }

            if (!Annotations.CanSetAnnotation(
                    RelationalFullAnnotationNames.Instance.DefaultValue,
                    ProviderFullAnnotationNames?.DefaultValue,
                    value))
            {
                return(false);
            }

            if (ShouldThrowOnConflict)
            {
                if (GetDefaultValueSql(false) != null)
                {
                    throw new InvalidOperationException(
                              RelationalStrings.ConflictingColumnServerGeneration(nameof(DefaultValue), Property.Name, nameof(DefaultValueSql)));
                }
                if (GetComputedColumnSql(false) != null)
                {
                    throw new InvalidOperationException(
                              RelationalStrings.ConflictingColumnServerGeneration(nameof(DefaultValue), Property.Name, nameof(ComputedColumnSql)));
                }
            }
            else if (value != null &&
                     (!CanSetDefaultValueSql(null) ||
                      !CanSetComputedColumnSql(null)))
            {
                return(false);
            }

            return(true);
        }