Linq to Sql GroupJoin Paging Strangeness

I noticed a weird Sql translation in the LinqToSql query that I was trying to optimize.

If I performed the following

Recipients.GroupJoin(
        RecipientAttributes, 
        x => x.Recipient_Id, 
        y => y.Recipient_Id, 
        (x,y) => new {Recipient = x, Attributes = y})
    .Skip(1)
    .Take(1000)

It executes in a single request, as expected.

However

Recipients.GroupJoin(
        RecipientAttributes, 
        x => x.Recipient_Id, 
        y => y.Recipient_Id, 
        (x,y) => new {Recipient = x, Attributes = y})
    .Skip(0)
    .Take(1000)

runs in a separate request for each attribute selection.

Removing gaps (0) also does not matter.

Can someone explain this and is there something I can do to get the first page request running in a single sql statement?

+3
source share

Source: https://habr.com/ru/post/1745065/


All Articles