Skip to content

Commit

Permalink
RevEng: Do not generate redundant ColumnName/Type in fluent API (#22173)
Browse files Browse the repository at this point in the history
Resolves #22122
  • Loading branch information
smitpatel authored Aug 22, 2020
1 parent 2c4fd98 commit 8d09961
Show file tree
Hide file tree
Showing 4 changed files with 1,025 additions and 349 deletions.
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

0 comments on commit 8d09961

Please sign in to comment.