public void Throws_setting_identity_generation_for_invalid_type()
        {
            var modelBuilder = GetModelBuilder();

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

            Assert.Equal(
                MySqlStrings.IdentityBadType("Name", nameof(Customer), "string"),
                Assert.Throws <ArgumentException>(
                    () => property.SetValueGenerationStrategy(MySqlValueGenerationStrategy.IdentityColumn)).Message);
        }
        public void Throws_setting_identity_generation_for_invalid_type_only_with_explicit()
        {
            var propertyBuilder = CreateBuilder()
                                  .Entity(typeof(Splot), ConfigurationSource.Convention)
                                  .Property("Name", typeof(string), ConfigurationSource.Convention);

            Assert.False(
                propertyBuilder.MySql(ConfigurationSource.Convention)
                .ValueGenerationStrategy(MySqlValueGenerationStrategy.IdentityColumn));

            Assert.Equal(
                MySqlStrings.IdentityBadType("Name", nameof(Splot), "string"),
                Assert.Throws <ArgumentException>(
                    () => propertyBuilder.MySql(ConfigurationSource.Explicit).ValueGenerationStrategy(MySqlValueGenerationStrategy.IdentityColumn)).Message);
        }
Пример #3
0
        public void Throws_setting_identity_generation_for_invalid_type_only_with_explicit()
        {
            var propertyBuilder = CreateBuilder()
                                  .Entity(typeof(Splot))
                                  .Property(typeof(string), "Name");

            Assert.Equal(
                MySqlStrings.IdentityBadType("Name", nameof(Splot), "string"),
                Assert.Throws <ArgumentException>(
                    () => propertyBuilder.HasValueGenerationStrategy(MySqlValueGenerationStrategy.IdentityColumn)).Message);

            Assert.Equal(
                MySqlStrings.IdentityBadType("Name", nameof(Splot), "string"),
                Assert.Throws <ArgumentException>(
                    () => new PropertyBuilder((IMutableProperty)propertyBuilder.Metadata).UseIdentityColumn()).Message);
        }
Пример #4
0
        private static void CheckValueGenerationStrategy(IProperty property, MySqlValueGenerationStrategy?value)
        {
            if (value != null)
            {
                var propertyType = property.ClrType;

                if (value == MySqlValueGenerationStrategy.IdentityColumn &&
                    !IsCompatibleIdentityColumn(property))
                {
                    throw new ArgumentException(
                              MySqlStrings.IdentityBadType(
                                  property.Name, property.DeclaringEntityType.DisplayName(), propertyType.ShortDisplayName()));
                }

                if (value == MySqlValueGenerationStrategy.ComputedColumn &&
                    !IsCompatibleComputedColumn(property))
                {
                    throw new ArgumentException(
                              MySqlStrings.ComputedBadType(
                                  property.Name, property.DeclaringEntityType.DisplayName(), propertyType.ShortDisplayName()));
                }
            }
        }