Skip to content
Open
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 @@ -557,11 +557,12 @@ protected override Expression VisitExtension(Expression extensionExpression)
if (_indexBasedBinding)
{
_clientProjections!.Add(jsonQuery);

return collectionResult.Update(
new ProjectionBindingExpression(_selectExpression, _clientProjections.Count - 1, collectionResult.Type));
}
else
{
_projectionMapping[_projectionMembers.Peek()] = jsonQuery;
}

_projectionMapping[_projectionMembers.Peek()] = jsonQuery;

return collectionResult.Update(
new ProjectionBindingExpression(_selectExpression, _projectionMembers.Peek(), collectionResult.Type));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,75 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

#endregion 38077

#region 38928

[Fact]
public virtual async Task Project_json_complex_collection_together_with_collection_navigation()
{
var contextFactory = await InitializeNonSharedTest<Context38928>(
seed: async context =>
{
context.Set<Context38928.Parent>().Add(
new Context38928.Parent
{
Items = [new Context38928.ChildItem { Value = "/x" }],
Links = [new Context38928.Link()]
});

await context.SaveChangesAsync();
});

await using var context = contextFactory.CreateDbContext();

var result = await context.Set<Context38928.Parent>()
.AsSplitQuery()
.Select(p => new
{
p.Id,
p.Items,
Links = p.Links.Select(l => new { l.Id }).ToList()
})
.SingleAsync();

Assert.NotEqual(0, result.Id);
Assert.NotNull(result.Items);
var item = Assert.Single(result.Items);
Assert.Equal("/x", item.Value);
Assert.Single(result.Links);
}

private class Context38928(DbContextOptions options) : DbContext(options)
{
public class Parent
{
public int Id { get; set; }
public List<ChildItem>? Items { get; set; }
public List<Link> Links { get; set; } = [];
}

public class ChildItem
{
public required string Value { get; init; }
}

public class Link
{
public int Id { get; set; }
public List<Parent> Parents { get; set; } = [];
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Parent>(b =>
{
b.ComplexCollection(p => p.Items).ToJson();
b.HasMany(p => p.Links).WithMany(l => l.Parents).UsingEntity("ParentLinks");
});
}
}

#endregion 38928

protected TestSqlLoggerFactory TestSqlLoggerFactory
=> (TestSqlLoggerFactory)ListLoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,33 @@ FROM [Child] AS [c]
""");
}

public override async Task Project_json_complex_collection_together_with_collection_navigation()
{
await base.Project_json_complex_collection_together_with_collection_navigation();

AssertSql(
"""
SELECT TOP(2) [p].[Id], [p].[Items]
FROM [Parent] AS [p]
ORDER BY [p].[Id]
""",
//
"""
SELECT [s].[Id], [p3].[Id]
FROM (
SELECT TOP(1) [p].[Id]
FROM [Parent] AS [p]
ORDER BY [p].[Id]
) AS [p3]
INNER JOIN (
SELECT [l1].[Id], [p2].[ParentsId]
FROM [ParentLinks] AS [p2]
INNER JOIN [Link] AS [l1] ON [p2].[LinksId] = [l1].[Id]
) AS [s] ON [p3].[Id] = [s].[ParentsId]
ORDER BY [p3].[Id]
""");
}

#endregion Non-shared test resources

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1454,6 +1454,35 @@ public override async Task Complex_property_on_split_entity()
""");
}

public override async Task Project_json_complex_collection_together_with_collection_navigation()
{
await base.Project_json_complex_collection_together_with_collection_navigation();

AssertSql(
"""
SELECT "p"."Id", "p"."Items"
FROM "Parent" AS "p"
ORDER BY "p"."Id"
LIMIT 2
""",
//
"""
SELECT "s"."Id", "p3"."Id"
FROM (
SELECT "p"."Id"
FROM "Parent" AS "p"
ORDER BY "p"."Id"
LIMIT 1
) AS "p3"
INNER JOIN (
SELECT "l1"."Id", "p2"."ParentsId"
FROM "ParentLinks" AS "p2"
INNER JOIN "Link" AS "l1" ON "p2"."LinksId" = "l1"."Id"
) AS "s" ON "p3"."Id" = "s"."ParentsId"
ORDER BY "p3"."Id"
""");
}

#endregion Non-shared test resources

[Fact]
Expand Down
Loading