我有一个程序可以返回我需要的实体 ID。
(我决定创建此过程,因为应返回给最终用户的实体由相关实体过滤,但 EF Core 不支持相关实体过滤)。
然后我想使用这个 id 来获取我需要的实体及其相关实体。
我正在使用Any operator. In my opinion it should generate query like this:
WHERE id IN(1,2,3,4....)` 但它似乎没有像我想要的那样工作。
相反,它会返回警告,并包含以下信息:
任何条款无法翻译,将在本地进行评估
我该如何解决它?
我的代码如下:
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()
;
您可以先选择“Id”吗关联 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();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)