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

Convert Int32 identity seed value #25857

Merged
merged 1 commit into from
Sep 3, 2021
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
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