Skip to content
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 @@ -34,7 +34,8 @@ public override string BuildMoveDataSql<T>(
{
var q = new StringBuilder();

if (options.CopyGeneratedColumns)
var identityInsert = options.CopyGeneratedColumns && insertedColumns.Any(x => x.IsGenerated);
if (identityInsert)
{
q.AppendLine($"SET IDENTITY_INSERT {target.QuotedTableName} ON;");
}
Expand Down Expand Up @@ -129,7 +130,7 @@ public override string BuildMoveDataSql<T>(

q.AppendLine(";");

if (options.CopyGeneratedColumns)
if (identityInsert)
{
q.AppendLine($"SET IDENTITY_INSERT {target.QuotedTableName} OFF;");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal sealed class ColumnMetadata(IProperty property, SqlDialectBuilder dial

public Type ClrType { get; } = property.ClrType;

public bool IsGenerated { get; } = property.ValueGenerated == ValueGenerated.OnAdd;
public bool IsGenerated { get; } = property.ValueGenerated != ValueGenerated.Never;

public object? GetValue(object entity, BulkInsertOptions options)
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,26 @@ await _context.ExecuteBulkInsertAsync(entities, (SqlServerBulkInsertOptions _) =
}));
}
}

[SkippableTheory]
[CombinatorialData]
public async Task InsertEntities_WithGeneratedGuidId(InsertStrategy strategy)
{
// Arrange
var entities = new List<TestEntityWithGuidId>
{
new TestEntityWithGuidId { Id = Guid.NewGuid(), Name = $"{_run}_Entity1" },
new TestEntityWithGuidId { Id = Guid.NewGuid(), Name = $"{_run}_Entity2" }
};

// Act
var insertedEntities = await _context.InsertWithStrategyAsync(strategy, entities, configure => configure.CopyGeneratedColumns = true);

// Assert
insertedEntities.Should().BeEquivalentTo(entities,
o=> o
.RespectingRuntimeTypes()
.Excluding(e => e.Id)
);
}
}