Skip to content

Commit

Permalink
Add quirk
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers committed Feb 14, 2023
1 parent 581ad0d commit 77aac27
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ namespace Microsoft.EntityFrameworkCore.Migrations.Design;
/// </remarks>
public class CSharpSnapshotGenerator : ICSharpSnapshotGenerator
{
private static readonly bool QuirkEnabled30058
= AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue30058", out var enabled) && enabled;

private static readonly MethodInfo HasAnnotationMethodInfo
= typeof(ModelBuilder).GetRuntimeMethod(nameof(ModelBuilder.HasAnnotation), new[] { typeof(string), typeof(string) })!;

Expand Down Expand Up @@ -861,7 +864,7 @@ private void GenerateTableMapping(

var explicitName = tableNameAnnotation != null
|| entityType.BaseType == null
|| (entityType.GetMappingStrategy() == RelationalAnnotationNames.TpcMappingStrategy && entityType.IsAbstract())
|| (!QuirkEnabled30058 && (entityType.GetMappingStrategy() == RelationalAnnotationNames.TpcMappingStrategy && entityType.IsAbstract()))
|| entityType.BaseType.GetTableName() != tableName
|| hasOverrides;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -802,9 +802,7 @@ partial class Snapshot : ModelSnapshot
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasDefaultSchema("DefaultSchema")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
modelBuilder.HasAnnotation("Relational:MaxIdentifierLength", 128);

SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);

Expand All @@ -822,15 +820,15 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasIndex("PetsId");

b.ToTable("HumanPet", "DefaultSchema");
b.ToTable("HumanPet");
});

modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Animal", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasDefaultValueSql("NEXT VALUE FOR [DefaultSchema].[AnimalSequence]");
.HasDefaultValueSql("NEXT VALUE FOR [AnimalSequence]");

SqlServerPropertyBuilderExtensions.UseSequence(b.Property<int>("Id"));

Expand All @@ -853,7 +851,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)

b.HasIndex("FavoriteAnimalId");

b.ToTable("Human", "DefaultSchema");
b.ToTable("Human");
});

modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Pet", b =>
Expand All @@ -873,7 +871,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<string>("EducationLevel")
.HasColumnType("nvarchar(max)");

b.ToTable("Cat", "DefaultSchema");
b.ToTable("Cat");
});

modelBuilder.Entity("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Dog", b =>
Expand All @@ -883,7 +881,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<string>("FavoriteToy")
.HasColumnType("nvarchar(max)");

b.ToTable("Dog", "DefaultSchema");
b.ToTable("Dog");
});

modelBuilder.Entity("HumanPet", b =>
Expand Down Expand Up @@ -917,7 +915,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
""",
model =>
{
Assert.Equal(6, model.GetAnnotations().Count());
Assert.Equal(5, model.GetAnnotations().Count());
Assert.Equal(6, model.GetEntityTypes().Count());
var animalType = model.FindEntityType("Microsoft.EntityFrameworkCore.Migrations.ModelSnapshotSqlServerTest+Animal");
Expand Down

0 comments on commit 77aac27

Please sign in to comment.