EntityFramework Include ThenInclude 多个超慢 [duplicate]

EntityFramework Include ThenInclude Multiple Super Slow [duplicate]

提问人:Herman 提问时间:11/12/2023 更新时间:11/12/2023 访问量:33

问:

我有以下代码,其中包含多个.Include 和 .然后包含。

var query = _postUserRepository.TableNoTracking;

query = query.Where(x => x.User.Name.Contains(name));
query = query.Where(x => x.User.Email.Contains(email));
query = query.Where(x => x.JobPostId == jobPostId);
query = query.Where(x => x.JobPost.ExpiresAt > expiredDate);
query = query.Where(x => x.JobPost.UserId == userId);
query = query.Include(x => x.User)
                .ThenInclude(y => y.Languages);
query = query.Include(x => x.User)
                .ThenInclude(y => y.Skills);
query = query.Include(x => x.User)
                .ThenInclude(y => y.Educations);
query = query.Include(x => x.User)
                .ThenInclude(y => y.Resumes;
query = query.Include(x => x.User)
                .ThenInclude(y => y.Talent);

var list = query.Take(20).ToList()

我认为问题是因为多个.然后包含。

如何解决该问题?

.NET 实体框架

评论

0赞 Dai 11/12/2023
...此外,您的查询是不可 SARGable 的,因为您使用的是子字符串匹配。这总是会很慢。Contains
0赞 Dai 11/12/2023
...你为什么要做六次?!Include(x=>x.User)
0赞 Svyatoslav Danyliv 11/12/2023
用。单个查询与拆分查询AsSplitQuery()

答: 暂无答案