我正在嘗試執行此查詢
var userAndLovedOnesQuery = await (from uq in _context.Users
where uq.SubjectId == request.SubjectId
select new
{
user = (from p in _context.Persons
where p.Id == uq.PersonId
select p)
.Include(x => x.PrimaryPhoneNumber).FirstOrDefaultAsync(cancellationToken),
lovedones = (from profileGroup in _context.ProfileGroups where profileGroup.UserId == uq.Id
join profileGroupDetail in _context.ProfileGroupDetails on profileGroup.Id equals profileGroupDetail.ProfileGroupId
join person in _context.Persons on profileGroupDetail.PersonId equals person.Id
select person).Include(u => u.PrimaryPhoneNumber)
.ToListAsync(cancellationToken),
}).FirstOrDefaultAsync(cancellationToken);
我收到了這個錯誤。
The LINQ expression 'DbSet<Person>()
.Where(p => p.Id == u.PersonId)
.Include(x => x.PrimaryPhoneNumber)
.FirstOrDefaultAsync(__cancellationToken_1)' could no## Heading ##t be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information
有什么我做錯了嗎?
uj5u.com熱心網友回復:
替換.ToListAsync(cancellationToken)為.ToList()和。.FirstOrDefaultAsync(cancellationToken)_ 在投影.FirstOrDefault()中使用方法是錯誤的。async
var userAndLovedOnesQuery = await (
from uq in _context.Users
where uq.SubjectId == request.SubjectId
select new
{
user = (from p in _context.Persons
where p.Id == uq.PersonId
select p)
.Include(x => x.PrimaryPhoneNumber)
.FirstOrDefault(),
lovedones = (from profileGroup in _context.ProfileGroups where profileGroup.UserId == uq.Id
join profileGroupDetail in _context.ProfileGroupDetails on profileGroup.Id equals profileGroupDetail.ProfileGroupId
join person in _context.Persons on profileGroupDetail.PersonId equals person.Id
select person).Include(u => u.PrimaryPhoneNumber)
.ToList(),
}).FirstOrDefaultAsync(cancellationToken);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/481446.html
標籤:C# 实体框架 林克 实体框架核心 ef-core-3.1
