如何改善linq-to-sql查询

时间:2019-04-24 13:47:24

标签: linq linq-to-sql linqpad

我正在LINQPad中执行以下查询:

Tickets.GroupJoin(UserRoles, t => t.AuthorId, r => r.UserId, (ticket, roles) => new {
    AuthorId = ticket.AuthorId,
    AuthorRoles = roles.Select(r => r.Role).Distinct(),
    Message = ticket.Message,
    Replies = ticket.TicketReplies.GroupJoin(UserRoles, reply => reply.AuthorId, role => role.UserId, (reply, roles2) => new {
        AuthorId = reply.AuthorId,
        AuthorRoles = roles2.Select(r => r.Role).Distinct(),
        Message = reply.Message
    })
}).Take(1000)

其中AuthorIdstringAuthorRolesint的列表,而Messagestring。该查询执行得很糟糕。该查询导致从LINQPad发送了超过2000条查询。

  • 为什么LINQPad无法将其转换为单个SQL查询?
  • 我可以将查询的表述方式改为LINQPad以便更好地执行吗?

0 个答案:

没有答案