Skip to content

Commit

Permalink
Convert Int32 identity seed value
Browse files Browse the repository at this point in the history
Fixes #25589
  • Loading branch information
AndriySvyryd authored Sep 3, 2021
1 parent f8e94f2 commit 4e68ad1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
42 changes: 42 additions & 0 deletions src/EFCore.Design/Migrations/Internal/SnapshotModelProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ public SnapshotModelProcessor(
return _modelRuntimeInitializer.Initialize((IModel)model, designTime: true, validationLogger: null);
}

private void ProcessCollection(IEnumerable<IReadOnlyProperty> metadata, string version)
{
foreach (var element in metadata)
{
ProcessElement(element, version);
}
}

private void ProcessCollection(IEnumerable<IReadOnlyAnnotatable> metadata, string version)
{
foreach (var element in metadata)
Expand All @@ -90,6 +98,23 @@ private void ProcessCollection(IEnumerable<IReadOnlyAnnotatable> metadata, strin
}
}

private void ProcessElement(IReadOnlyModel model, string version)
{
ProcessElement((IReadOnlyAnnotatable)model, version);

if ((version.StartsWith("3.", StringComparison.Ordinal)
|| version.StartsWith("5.", StringComparison.Ordinal))
&& model is IMutableModel mutableModel)
{
var seed = model["SqlServer:IdentitySeed"];
if (seed != null
&& seed is int intSeed)
{
mutableModel["SqlServer:IdentitySeed"] = (long)intSeed;
}
}
}

private void ProcessElement(IReadOnlyEntityType entityType, string version)
{
ProcessElement((IReadOnlyAnnotatable)entityType, version);
Expand All @@ -103,6 +128,23 @@ private void ProcessElement(IReadOnlyEntityType entityType, string version)
}
}

private void ProcessElement(IReadOnlyProperty property, string version)
{
ProcessElement((IReadOnlyAnnotatable)property, version);

if ((version.StartsWith("3.", StringComparison.Ordinal)
|| version.StartsWith("5.", StringComparison.Ordinal))
&& property is IMutableProperty mutableProperty)
{
var seed = property["SqlServer:IdentitySeed"];
if (seed != null
&& seed is int intSeed)
{
mutableProperty["SqlServer:IdentitySeed"] = (long)intSeed;
}
}
}

private void ProcessElement(IReadOnlyAnnotatable? metadata, string version)
{
if (version.StartsWith("1.", StringComparison.Ordinal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1084,15 +1084,17 @@ protected override void BuildModel(ModelBuilder modelBuilder)
modelBuilder
.HasAnnotation("ProductVersion", "3.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn)
.HasAnnotation("SqlServer:IdentitySeed", 1);

modelBuilder.Entity(
"Ownership.OwningType1", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn)
.HasAnnotation("SqlServer:IdentitySeed", 1);
b.HasKey("Id");
Expand Down

0 comments on commit 4e68ad1

Please sign in to comment.