包括与其中EF核心/ ThenInclude

问题描述 投票:1回答:1

我需要在ThenInclude使用其中

        var templatesFields = await _context.Sections
        .Include(x => x.Subtitles)
        .ThenInclude(r => r.Fields.Where(t=>t.TemplatesFields.TemplateID==TemplateID))
        .ThenInclude(r => r.OptionSources)
        .ThenInclude(r => r.OptionsSourcesDetails)
        .ToListAsync();
entity-framework linq api asp.net-core .net-core
1个回答
1
投票

你不能使用WHERE条件内IncludeThenInclude。你可以做的是:

var templatesFields = await _context.Sections
    .Include(x => x.Subtitles)
    .ThenInclude(r => r.Fields)
    .ThenInclude(r => r.OptionSources)
    .ThenInclude(r => r.OptionsSourcesDetails)
    .Where(t=>t.Subtitles.Fields.Any(x => x.TemplatesFields.TemplateID==TemplateID))
    .ToListAsync();
© www.soinside.com 2019 - 2024. All rights reserved.