Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RevEng: Do not generate redundant ColumnName/Type in fluent API #22173

Merged
1 commit merged into from
Aug 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,10 @@ private void GenerateProperty(IProperty property, bool useDataAnnotations)
{
// Strip out any annotations handled as attributes - these are already handled when generating
// the entity's properties
// Only relational ones need to be removed here. Core ones are already removed by FilterIgnoredAnnotations
annotations.Remove(RelationalAnnotationNames.ColumnName);
annotations.Remove(RelationalAnnotationNames.ColumnType);

_ = _annotationCodeGenerator.GenerateDataAnnotationAttributes(property, annotations);
}
else
Expand Down Expand Up @@ -640,7 +644,8 @@ private void GenerateProperty(IProperty property, bool useDataAnnotations)

var valueGenerated = property.ValueGenerated;
var isRowVersion = false;
if (((IConventionProperty)property).GetValueGeneratedConfigurationSource().HasValue
if (((IConventionProperty)property).GetValueGeneratedConfigurationSource() is ConfigurationSource valueGeneratedConfigurationSource
&& valueGeneratedConfigurationSource != ConfigurationSource.Convention
&& RelationalValueGenerationConvention.GetValueGenerated(property) != valueGenerated)
{
var methodName = valueGenerated switch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void Empty_model()
new ModelCodeGenerationOptions(),
code =>
{
Assert.Equal(
AssertFileContents(
@"using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
Expand Down Expand Up @@ -63,8 +63,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
}
}
",
code.ContextFile.Code,
ignoreLineEndingDifferences: true);
code.ContextFile);

Assert.Empty(code.AdditionalFiles);
},
Expand All @@ -79,7 +78,7 @@ public void SuppressConnectionStringWarning_works()
new ModelCodeGenerationOptions { SuppressConnectionStringWarning = true },
code =>
{
Assert.Equal(
AssertFileContents(
@"using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
Expand Down Expand Up @@ -116,8 +115,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
}
}
",
code.ContextFile.Code,
ignoreLineEndingDifferences: true);
code.ContextFile);

Assert.Empty(code.AdditionalFiles);
},
Expand All @@ -132,7 +130,7 @@ public void SuppressOnConfiguring_works()
new ModelCodeGenerationOptions { SuppressOnConfiguring = true },
code =>
{
Assert.Equal(
AssertFileContents(
@"using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
Expand Down Expand Up @@ -161,11 +159,11 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
}
}
",
code.ContextFile.Code,
ignoreLineEndingDifferences: true);
code.ContextFile);

Assert.Empty(code.AdditionalFiles);
});
},
null);
}

[ConditionalFact]
Expand Down Expand Up @@ -448,7 +446,7 @@ public void Entity_with_indexes_and_use_data_annotations_false_always_generates_
new ModelCodeGenerationOptions { UseDataAnnotations = false },
code =>
{
Assert.Equal(
AssertFileContents(
@"using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
Expand Down Expand Up @@ -502,8 +500,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
}
}
",
code.ContextFile.Code,
ignoreLineEndingDifferences: true);
code.ContextFile);
},
model =>
Assert.Equal(2, model.FindEntityType("TestNamespace.EntityWithIndexes").GetIndexes().Count()));
Expand Down Expand Up @@ -532,7 +529,7 @@ public void Entity_with_indexes_and_use_data_annotations_true_generates_fluent_A
new ModelCodeGenerationOptions { UseDataAnnotations = true },
code =>
{
Assert.Equal(
AssertFileContents(
@"using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
Expand Down Expand Up @@ -583,8 +580,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
}
}
",
code.ContextFile.Code,
ignoreLineEndingDifferences: true);
code.ContextFile);
},
model =>
Assert.Equal(2, model.FindEntityType("TestNamespace.EntityWithIndexes").GetIndexes().Count()));
Expand Down Expand Up @@ -616,7 +612,7 @@ public void Entity_lambda_uses_correct_identifiers()
new ModelCodeGenerationOptions { UseDataAnnotations = false },
code =>
{
Assert.Equal(
AssertFileContents(
@"using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
Expand Down Expand Up @@ -659,8 +655,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

entity.Property(e => e.Id).UseIdentityColumn();

entity.Property(e => e.DependentId).ValueGeneratedNever();

entity.HasOne(d => d.NavigationToPrincipal)
.WithOne(p => p.NavigationToDependent)
.HasPrincipalKey<PrincipalEntity>(p => p.PrincipalId)
Expand All @@ -672,8 +666,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
entity.HasKey(e => e.AlternateId);

entity.Property(e => e.AlternateId).UseIdentityColumn();

entity.Property(e => e.Id).ValueGeneratedNever();
});

OnModelCreatingPartial(modelBuilder);
Expand All @@ -683,8 +675,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
}
}
",
code.ContextFile.Code,
ignoreLineEndingDifferences: true);
code.ContextFile);
},
model => { });
}
Expand Down
Loading