【发布时间】:2022-04-02 07:14:00
【问题描述】:
我有一个程序可以返回我需要的实体 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()
;
【问题讨论】:
-
var assocsIds = await _context.Assoc.AsNoTracking() .FromSql($"exec {SqlProcedures.GetAssocsForIndexProc} {query.IndexMviId}, {query.FilterByGroupId}") .ToListAsync() var bob = assocsIds.Select(z => z.Id).ToList(); var productAssocs = await _context.Assoc .Where(x => bob.Contains(x.Id) .etc etc工作吗?
标签: c# entity-framework asp.net-core entity-framework-core