无法翻译长表达式

The long expression could not be translated

我正在尝试执行此查询


    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

我做错了什么吗?

.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);