Multi包含超时

本文关键字:超时 包含 Multi | 更新日期: 2023-09-27 18:13:20

我正在使用EF 6.1.1,我正在尝试使用下面的LINQ查询拉回数据。我可以用不到30行手工编写这个查询,但实体框架正在做数千。看看下面的SQL,我错过了什么吗?

LINQ

_UserRepository
            .Query()
            .Include(a => a.PaymentSchedules)
            .Include(a => a.Profile.ProfileImages)
            .Include(a => a.Profile.ProfileImages.Select(c => c.Image.HomePageImage))  //<<< this causes 100+ joins
            .Include(a => a.Profile.ProfileImages.Select(i => i.Image.HoverOverImage)) //<<< this causes 100+ joins
            .AsQueryable()
            .Where(a => a.PaymentSchedules.Any(p => p.Active == true && p.DatePaid > eighthOfMonth))
            .Where(a => a.Profile.ProfileImages.Any(prof => prof.CurrentImage == true))
            .Select(a => a.Profile)
            .OrderBy(a => a.Id) //require for using skip
            .Skip(skipInt)
            .Take(takeInt)
            .ToList();

**Stackoverflow甚至不允许我发布SQL,因为它大于100K字符并且包含超过200个左连接!!

请帮助。

**编辑:复制粘贴失败

Multi包含超时

EF非常强大,但我不喜欢像这样包含许多连接或包含的非常复杂的查询,我更喜欢使用Dapper(更快)。

https://github.com/StackExchange/dapper-dot-net

此外,您可以将查询拆分为更小的查询,例如:在单独的查询中获取ProfileImages然后PaymentSchedules ..