Skip to content

Commit 40757ed

Browse files
committed
Merge in 'release/7.0' changes
2 parents 3317439 + dd2c6c3 commit 40757ed

File tree

7 files changed

+444
-7
lines changed

7 files changed

+444
-7
lines changed

src/EFCore.SqlServer/Update/Internal/SqlServerModificationCommandBatch.cs

+17-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public class SqlServerModificationCommandBatch : AffectedCountModificationComman
2525

2626
private readonly List<IReadOnlyModificationCommand> _pendingBulkInsertCommands = new();
2727

28+
private static readonly bool QuirkEnabled29502
29+
= AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue29502", out var enabled) && enabled;
30+
2831
/// <summary>
2932
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
3033
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
@@ -116,9 +119,21 @@ private void ApplyPendingBulkInsertCommands()
116119
ResultSetMappings.Add(resultSetMapping);
117120
}
118121

119-
if (resultSetMapping != ResultSetMapping.NoResults)
122+
// All result mappings are marked as "not last", mark the last one as "last".
123+
if (QuirkEnabled29502)
124+
{
125+
if (resultSetMapping != ResultSetMapping.NoResults)
126+
{
127+
ResultSetMappings[^1] = ResultSetMapping.LastInResultSet;
128+
}
129+
}
130+
else
120131
{
121-
ResultSetMappings[^1] = ResultSetMapping.LastInResultSet;
132+
if (resultSetMapping.HasFlag(ResultSetMapping.HasResultRow))
133+
{
134+
ResultSetMappings[^1] &= ~ResultSetMapping.NotLastInResultSet;
135+
ResultSetMappings[^1] |= ResultSetMapping.LastInResultSet;
136+
}
122137
}
123138
}
124139

test/EFCore.Relational.Specification.Tests/Update/NonSharedModelUpdatesTestBase.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ protected override string StoreName
1212
=> "NonSharedModelUpdatesTestBase";
1313

1414
[ConditionalTheory] // Issue #29356
15-
[InlineData(false)]
16-
[InlineData(true)]
15+
[MemberData(nameof(IsAsyncData))]
1716
public virtual async Task Principal_and_dependent_roundtrips_with_cycle_breaking(bool async)
1817
{
1918
var contextFactory = await InitializeAsync<DbContext>(

test/EFCore.SqlServer.FunctionalTests/EFCore.SqlServer.FunctionalTests.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
<None Update="SqlAzure\adventureworks.sql">
5050
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5151
</None>
52+
<None Update="Update\Issue29502.sql">
53+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
54+
</None>
5255
<None Update="config.json">
5356
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5457
</None>

test/EFCore.SqlServer.FunctionalTests/TestUtilities/SqlServerTestStore.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ public static SqlServerTestStore GetOrCreateInitialized(string name)
2929
public static SqlServerTestStore GetOrCreateWithInitScript(string name, string initScript)
3030
=> new(name, initScript: initScript);
3131

32-
public static SqlServerTestStore GetOrCreateWithScriptPath(string name, string scriptPath, bool? multipleActiveResultSets = null)
33-
=> new(name, scriptPath: scriptPath, multipleActiveResultSets: multipleActiveResultSets);
32+
public static SqlServerTestStore GetOrCreateWithScriptPath(
33+
string name,
34+
string scriptPath,
35+
bool? multipleActiveResultSets = null,
36+
bool shared = true)
37+
=> new(name, scriptPath: scriptPath, multipleActiveResultSets: multipleActiveResultSets, shared: shared);
3438

3539
public static SqlServerTestStore Create(string name, bool useFileName = false)
3640
=> new(name, useFileName, shared: false);

test/EFCore.SqlServer.FunctionalTests/Update/Issue29502.sql

+370
Large diffs are not rendered by default.

test/EFCore.SqlServer.FunctionalTests/Update/NonSharedModelUpdatesSqlServerTest.cs

+46
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,52 @@ OUTPUT 1
8484
""");
8585
}
8686

87+
[ConditionalFact] // Issue #29502
88+
public virtual async Task Bulk_insert_result_set_mapping()
89+
{
90+
var contextFactory = await InitializeAsync<DbContext>(
91+
onModelCreating: mb =>
92+
{
93+
mb.Entity<User>().ToTable("Users");
94+
mb.Entity<DailyDigest>().ToTable("DailyDigests");
95+
},
96+
createTestStore: () => SqlServerTestStore.GetOrCreateWithScriptPath(
97+
"Issue29502",
98+
Path.Combine("Update", "Issue29502.sql"),
99+
shared: false));
100+
101+
await ExecuteWithStrategyInTransactionAsync(
102+
contextFactory,
103+
async context =>
104+
{
105+
var digests = await context.Set<User>()
106+
.OrderBy(u => u.TimeCreatedUtc)
107+
.Take(23)
108+
.Select(u => new DailyDigest { User = u })
109+
.ToListAsync();
110+
111+
foreach (var digest in digests)
112+
{
113+
context.Set<DailyDigest>().Add(digest);
114+
}
115+
116+
await context.SaveChangesAsync();
117+
});
118+
}
119+
120+
public class User
121+
{
122+
public string Id { get; set; } = null!;
123+
public DateTime TimeCreatedUtc { get; set; }
124+
public ICollection<DailyDigest> DailyDigests { get; set; } = null!;
125+
}
126+
127+
public class DailyDigest
128+
{
129+
public int Id { get; set; }
130+
public User User { get; set; }
131+
}
132+
87133
private void AssertSql(params string[] expected)
88134
=> TestSqlLoggerFactory.AssertBaseline(expected);
89135

test/EFCore.Sqlite.FunctionalTests/Update/NonSharedModelUpdatesSqliteTest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Microsoft.EntityFrameworkCore.Update;
55

6-
public class NonSharedModelUpdatesSqlServerTest : NonSharedModelUpdatesTestBase
6+
public class NonSharedModelUpdatesSqliteTest : NonSharedModelUpdatesTestBase
77
{
88
public override async Task Principal_and_dependent_roundtrips_with_cycle_breaking(bool async)
99
{

0 commit comments

Comments
 (0)