Skip to content

Commit 8ce6ba2

Browse files
committed
Adapt JSON collection fix for release/11.0
Allow moved entries after newly added slots and use the release branch's nested JSON collection model in regression tests.
1 parent 2d01019 commit 8ce6ba2

4 files changed

Lines changed: 17 additions & 13 deletions

File tree

‎src/EFCore/ChangeTracking/Internal/ChangeDetector.cs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,9 @@ public bool DetectComplexCollectionChanges(InternalEntryBase entry, IComplexProp
495495
else
496496
{
497497
Check.DebugAssert(
498-
originalEntry.Ordinal > i || currentNulls.Contains(originalEntry.Ordinal),
498+
originalEntry.Ordinal > i
499+
|| currentNulls.Contains(originalEntry.Ordinal)
500+
|| added.Contains(originalEntry.Ordinal),
499501
$"Expected the entry that was previously at {originalEntry.Ordinal} to have been encountered at an ordinal before {i}.");
500502
var previousOrdinal = originalEntry.Ordinal;
501503
entry.MoveComplexCollectionEntry(complexProperty, previousOrdinal, i);

‎test/EFCore.Relational.Specification.Tests/Update/ComplexCollectionJsonUpdateTestBase.cs‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,23 @@ public virtual Task Prepend_and_evict_json_complex_collection_element_after_dete
7979
async context =>
8080
{
8181
var company = await context.Companies.OrderBy(c => c.Id).FirstAsync().ConfigureAwait(false);
82-
var widget = await context.StructWidgets.SingleAsync().ConfigureAwait(false);
82+
var widget = await context.Widgets.SingleAsync().ConfigureAwait(false);
8383
company.Contacts = [new() { Name = "t0" }, new() { Name = "t1" }, new() { Name = "t2" }, new() { Name = "t3" }];
84-
widget.Data = new StructData
84+
widget.Deep = new DeepData
8585
{
86-
Label = "S1",
87-
Tags = [new() { Value = "t0" }, new() { Value = "t1" }, new() { Value = "t2" }, new() { Value = "t3" }]
86+
Mid = new MiddleData
87+
{
88+
Items = [new() { Title = "t0" }, new() { Title = "t1" }, new() { Title = "t2" }, new() { Title = "t3" }]
89+
}
8890
};
8991
await context.SaveChangesAsync().ConfigureAwait(false);
9092
},
9193
async context =>
9294
{
9395
var company = await context.Companies.OrderBy(c => c.Id).FirstAsync().ConfigureAwait(false);
94-
var widget = await context.StructWidgets.SingleAsync().ConfigureAwait(false);
96+
var widget = await context.Widgets.SingleAsync().ConfigureAwait(false);
9597
company.Contacts = [new() { Name = "new" }, .. company.Contacts!.Take(3)];
96-
widget.Data = new StructData { Label = widget.Data.Label, Tags = [new() { Value = "new" }, .. widget.Data.Tags.Take(3)] };
98+
widget.Deep.Mid.Items = [new() { Title = "new" }, .. widget.Deep.Mid.Items.Take(3)];
9799

98100
context.ChangeTracker.DetectChanges();
99101
ClearLog();
@@ -104,9 +106,9 @@ public virtual Task Prepend_and_evict_json_complex_collection_element_after_dete
104106
using (SuspendRecordingEvents())
105107
{
106108
var company = await context.Companies.OrderBy(c => c.Id).FirstAsync().ConfigureAwait(false);
107-
var widget = await context.StructWidgets.SingleAsync().ConfigureAwait(false);
109+
var widget = await context.Widgets.SingleAsync().ConfigureAwait(false);
108110
Assert.Equal(["new", "t0", "t1", "t2"], company.Contacts!.Select(c => c.Name));
109-
Assert.Equal(["new", "t0", "t1", "t2"], widget.Data.Tags.Select(t => t.Value));
111+
Assert.Equal(["new", "t0", "t1", "t2"], widget.Deep.Mid.Items.Select(i => i.Title));
110112
}
111113
});
112114

‎test/EFCore.SqlServer.FunctionalTests/Update/ComplexCollectionJsonUpdateSqlServerTest.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ public override async Task Prepend_and_evict_json_complex_collection_element_aft
3535
"""
3636
@p0='[{"Name":"new","PhoneNumbers":[]},{"Name":"t0","PhoneNumbers":[]},{"Name":"t1","PhoneNumbers":[]},{"Name":"t2","PhoneNumbers":[]}]' (Nullable = false) (Size = 130)
3737
@p1='1'
38-
@p2='{"Label":"S1","Tags":[{"Value":"new"},{"Value":"t0"},{"Value":"t1"},{"Value":"t2"}]}' (Nullable = false) (Size = 84)
38+
@p2='{"Mid":{"Items":[{"Title":"new","Inner":[],"Others":[]},{"Title":"t0","Inner":[],"Others":[]},{"Title":"t1","Inner":[],"Others":[]},{"Title":"t2","Inner":[],"Others":[]}]}}' (Nullable = false) (Size = 172)
3939
@p3='1'
4040
4141
SET NOCOUNT ON;
4242
UPDATE [Companies] SET [Contacts] = @p0
4343
OUTPUT 1
4444
WHERE [Id] = @p1;
45-
UPDATE [StructWidgets] SET [Data] = @p2
45+
UPDATE [Widgets] SET [Deep] = @p2
4646
OUTPUT 1
4747
WHERE [Id] = @p3;
4848
""");

‎test/EFCore.Sqlite.FunctionalTests/Update/ComplexCollectionJsonUpdateSqliteTest.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public override async Task Prepend_and_evict_json_complex_collection_element_aft
3939
RETURNING 1;
4040
""",
4141
"""
42-
@p0='{"Label":"S1","Tags":[{"Value":"new"},{"Value":"t0"},{"Value":"t1"},{"Value":"t2"}]}' (Nullable = false) (Size = 84)
42+
@p0='{"Mid":{"Items":[{"Title":"new","Inner":[],"Others":[]},{"Title":"t0","Inner":[],"Others":[]},{"Title":"t1","Inner":[],"Others":[]},{"Title":"t2","Inner":[],"Others":[]}]}}' (Nullable = false) (Size = 172)
4343
@p1='1'
4444
45-
UPDATE "StructWidgets" SET "Data" = @p0
45+
UPDATE "Widgets" SET "Deep" = @p0
4646
WHERE "Id" = @p1
4747
RETURNING 1;
4848
""");

0 commit comments

Comments
 (0)