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

Generate identity SQL for different seeds in TPC #28742

Merged
merged 1 commit into from
Aug 16, 2022
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 @@ -741,7 +741,7 @@ internal static SqlServerValueGenerationStrategy GetValueGenerationStrategy(
{
return (SqlServerValueGenerationStrategy?)@override.Value ?? SqlServerValueGenerationStrategy.None;
}

var annotation = property.FindAnnotation(SqlServerAnnotationNames.ValueGenerationStrategy);
if (annotation?.Value != null
&& StoreObjectIdentifier.Create(property.DeclaringEntityType, storeObject.StoreObjectType) == storeObject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,7 @@ public override IEnumerable<IAnnotation> For(IColumn column, bool designTime)
}

var table = StoreObjectIdentifier.Table(column.Table.Name, column.Table.Schema);
var identityProperty = column.PropertyMappings.Where(
m => m.TableMapping.EntityType == m.Property.DeclaringEntityType)
var identityProperty = column.PropertyMappings
.Select(m => m.Property)
.FirstOrDefault(
p => p.GetValueGenerationStrategy(table)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,59 @@ await Test(
@"ALTER TABLE [People] ADD [IdentityColumn] int NOT NULL IDENTITY(100, 5);");
}

[ConditionalFact]
public virtual async Task Add_column_identity_seed_increment_for_TPC()
{
await Test(
builder =>
{
builder.Entity("Animal").UseTpcMappingStrategy().Property<string>("Id");
builder.Entity("Cat").HasBaseType("Animal").ToTable("Cats");
builder.Entity("Dog").HasBaseType("Animal").ToTable("Dogs");
},
builder => { },
builder =>
{
builder.Entity("Animal")
.Property<int>("IdentityColumn");
builder.Entity("Cat").ToTable("Cats", tb => tb.Property("IdentityColumn").UseIdentityColumn(1, 2));
builder.Entity("Dog").ToTable("Dogs", tb => tb.Property("IdentityColumn").UseIdentityColumn(2, 2));
},
model =>
{
Assert.Collection(model.Tables,
t =>
{
Assert.Equal("Animal", t.Name);
var column = Assert.Single(t.Columns, c => c.Name == "IdentityColumn");
Assert.Null(column.ValueGenerated);
},
t =>
{
Assert.Equal("Cats", t.Name);
var column = Assert.Single(t.Columns, c => c.Name == "IdentityColumn");
Assert.Equal(ValueGenerated.OnAdd, column.ValueGenerated);
// TODO: Do we not reverse-engineer identity facets?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. It was a community PR, and we just filed an issue to do it later.

// Assert.Equal(100, column[SqlServerAnnotationNames.IdentitySeed]);
// Assert.Equal(5, column[SqlServerAnnotationNames.IdentityIncrement]);
},
t =>
{
Assert.Equal("Dogs", t.Name);
var column = Assert.Single(t.Columns, c => c.Name == "IdentityColumn");
Assert.Equal(ValueGenerated.OnAdd, column.ValueGenerated);
// TODO: Do we not reverse-engineer identity facets?
// Assert.Equal(100, column[SqlServerAnnotationNames.IdentitySeed]);
// Assert.Equal(5, column[SqlServerAnnotationNames.IdentityIncrement]);
});
});

AssertSql(
@"ALTER TABLE [Dogs] ADD [IdentityColumn] int NOT NULL IDENTITY(2, 2);",
"ALTER TABLE [Cats] ADD [IdentityColumn] int NOT NULL IDENTITY(1, 2);",
"ALTER TABLE [Animal] ADD [IdentityColumn] int NOT NULL DEFAULT 0;");
}

public override async Task Alter_column_change_type()
{
await base.Alter_column_change_type();
Expand Down