-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Open
Labels
Milestone
Description
Max can be used over a collection navigation in a projection:
_ = await ctx.Authors
.Select(a => new { Author = a, Books = a.Books.Max(b => b.Id) })
.ToArrayAsync();SELECT [a].[Id], [a].[Name], (
SELECT MAX([b].[Id])
FROM [Books] AS [b]
WHERE [a].[Id] = [b].[AuthorId]) AS [Books]
FROM [Authors] AS [a]However, the same can't be done with string.Join:
_ = await ctx.Authors
.Select(a => new { Author = a, Books = string.Join(", ", a.Books.Select(b => b.Name)) })
.ToArrayAsync();(this causes client evaluation)
The query above can be rewritten using a GroupBy, which does work:
_ = await ctx.Books
.GroupBy(b => b.Author)
.Select(g => new { Author = g.Key, Books = string.Join(", ", g.Select(b => b.Name)) })
.ToArrayAsync();Reactions are currently unavailable