public virtual void Detects_primary_key_with_default_value()
        {
            var model   = CreateConventionlessModelBuilder().Model;
            var entityA = model.AddEntityType(typeof(A));

            SetPrimaryKey(entityA);
            entityA.FindProperty("Id").Relational().DefaultValue = 1;

            VerifyWarning(RelationalResources.LogKeyHasDefaultValue(new TestLogger <RelationalLoggingDefinitions>()).GenerateMessage("Id", "A"), model);
        }
Esempio n. 2
0
        public virtual void Detects_alternate_key_with_default_value()
        {
            var model   = CreateConventionlessModelBuilder().Model;
            var entityA = model.AddEntityType(typeof(A));

            SetPrimaryKey(entityA);

            var property = entityA.AddProperty("P0", typeof(int?));

            property.IsNullable = false;
            entityA.AddKey(new[] { property });
            property.SetDefaultValue(1);

            VerifyWarning(RelationalResources.LogKeyHasDefaultValue(new TestLogger <TestRelationalLoggingDefinitions>()).GenerateMessage("P0", "A"), model);
        }
Esempio n. 3
0
        public virtual ModelBuilder Default_for_key_string_column_throws()
        {
            var modelBuilder = CreateModelBuilder();

            modelBuilder.Entity <Login1>().Property(l => l.UserName).HasDefaultValue("default");
            modelBuilder.Ignore <Profile1>();

            Assert.Equal(
                CoreStrings.WarningAsErrorTemplate(
                    RelationalEventId.ModelValidationKeyDefaultValueWarning,
                    RelationalResources.LogKeyHasDefaultValue(new TestLogger <SqlServerLoggingDefinitions>()).GenerateMessage(nameof(Login1.UserName), nameof(Login1)),
                    "RelationalEventId.ModelValidationKeyDefaultValueWarning"),
                Assert.Throws <InvalidOperationException>(() => Validate(modelBuilder)).Message);

            return(modelBuilder);
        }
Esempio n. 4
0
        public void SqlServerValueGenerationStrategy_warns_when_setting_conflicting_DefaultValue(
            SqlServerValueGenerationStrategy sqlServerValueGenerationStrategy)
        {
            var modelBuilder = CreateConventionalModelBuilder();

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

            propertyBuilder.Metadata.SetValueGenerationStrategy(sqlServerValueGenerationStrategy);
            ConfigureProperty(propertyBuilder.Metadata, "DefaultValue", "2");

            VerifyWarnings(new[] {
                SqlServerResources.LogConflictingValueGenerationStrategies(new TestLogger <SqlServerLoggingDefinitions>())
                .GenerateMessage(sqlServerValueGenerationStrategy.ToString(), "DefaultValue", "Id", nameof(Dog)),
                RelationalResources.LogKeyHasDefaultValue(new TestLogger <SqlServerLoggingDefinitions>())
                .GenerateMessage("Id", nameof(Dog))
            },
                           modelBuilder.Model);
        }