繁体   English   中英

EF核心,Any无法翻译,将在本地进行评估

[英]EF core, Any could not be translated and will be evaluated locally

我有返回我需要的实体ID的过程。

(我决定创建此过程,因为应归还给最终用户的实体由相关实体过滤,但是ef core不支持相关实体过滤)。

然后,我想使用此ID来获取我需要其相关实体的实体。

我正在使用“任何”运算符。 在我看来,它应该生成这样的查询:“ WHERE id IN(1,2,3,4 ....)”,但看来,它不能像我想要的那样工作。

而是,它返回警告,并带有以下信息:“ Any子句无法翻译,将在本地求值”

我该如何解决?

我的代码如下:

            var assocsIds = await _context.Assoc.AsNoTracking()
            .FromSql($"exec {SqlProcedures.GetAssocsForIndexProc} {query.IndexMviId}, {query.FilterByGroupId}")
            .ToListAsync()

            var productAssocs = await _context.Assoc
                .Where(x => assocsIds.Any(z => z.Id == x.Id))
                .Include(x => x.Attribute)
                .ThenInclude(x => x.Translation)
                .Include(x => x.Option)
                .ThenInclude(x => x.Translation)
                .Include(x => x.Mvi)
                .ThenInclude(x => x.Translation)
                .AsNoTracking()
                .ToListAsync()
            ;

您可以先从assocsIds中选择“ Id”到另一个变量中,然后尝试以下操作吗?

var productAssocs = await _context.Assoc
            .Where(x => yourIdsList.Contains(x.Id))
            .Include(x => x.Attribute)
            .ThenInclude(x => x.Translation)
            .Include(x => x.Option)
            .ThenInclude(x => x.Translation)
            .Include(x => x.Mvi)
            .ThenInclude(x => x.Translation)
            .AsNoTracking()
            .ToListAsync();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM