/// <summary>
 /// 设置值生成策略
 /// </summary>
 /// <param name="value">值生成策略</param>
 /// <returns></returns>
 protected virtual bool SetValueGenerationStrategy(OracleValueGenerationStrategy?value)
 {
     if (value.HasValue)
     {
         Type clrType = Property.ClrType;
         if (value == OracleValueGenerationStrategy.IdentityColumn && !IsCompatibleIdentityColumn(Property))
         {
             if (ShouldThrowOnInvalidConfiguration)
             {
                 throw new ArgumentException(OracleStrings.IdentityBadType(Property.Name, Property.DeclaringEntityType.DisplayName(), clrType.ShortDisplayName()));
             }
             return(false);
         }
         if (value == OracleValueGenerationStrategy.SequenceHiLo && !IsCompatibleSequenceHiLo(Property))
         {
             if (ShouldThrowOnInvalidConfiguration)
             {
                 throw new ArgumentException(OracleStrings.SequenceBadType(Property.Name, Property.DeclaringEntityType.DisplayName(), clrType.ShortDisplayName()));
             }
             return(false);
         }
     }
     if (!CanSetValueGenerationStrategy(value))
     {
         return(false);
     }
     if (!ShouldThrowOnConflict && ValueGenerationStrategy != value && value.HasValue)
     {
         ClearAllServerGeneratedValues();
     }
     return(Annotations.SetAnnotation(OracleAnnotationNames.ValueGenerationStrategy, value));
 }
Пример #2
0
        public void Throws_setting_sequence_generation_for_invalid_type()
        {
            var modelBuilder = GetModelBuilder();

            var property = modelBuilder
                           .Entity <Customer>()
                           .Property(e => e.Name)
                           .Metadata;

            Assert.Equal(
                OracleStrings.SequenceBadType("Name", nameof(Customer), "string"),
                Assert.Throws <ArgumentException>(
                    () => property.Oracle().ValueGenerationStrategy = OracleValueGenerationStrategy.SequenceHiLo).Message);
        }
Пример #3
0
        public void Throws_setting_sequence_generation_for_invalid_type_only_with_explicit()
        {
            var propertyBuilder = CreateBuilder()
                                  .Entity(typeof(Splot), ConfigurationSource.Convention)
                                  .Property("Name", typeof(string), ConfigurationSource.Convention);

            Assert.False(propertyBuilder.Oracle(ConfigurationSource.Convention)
                         .ValueGenerationStrategy(OracleValueGenerationStrategy.SequenceHiLo));

            Assert.Equal(
                OracleStrings.SequenceBadType("Name", nameof(Splot), "string"),
                Assert.Throws <ArgumentException>(
                    () => propertyBuilder.Oracle(ConfigurationSource.Explicit).ValueGenerationStrategy(OracleValueGenerationStrategy.SequenceHiLo)).Message);
        }