gpt4 book ai didi

c# - 如何向 ThenInclude 添加 where 子句

转载 作者:太空狗 更新时间:2023-10-29 17:45:46 25 4
gpt4 key购买 nike

<分区>

我有 3 个实体:

Questionnaire.cs:

public class Questionnaire
{
public int Id { get; set; }
public string Name { get; set; }
public ICollection<Question> Questions { get; set; }
}

问题.cs:

public class Question
{
public int Id { get; set; }
public string Text { get; set; }
public ICollection<Answer> Answers { get; set; }
}

Answer.cs:

public class Answer
{
public int Id { get; set; }
public string UserId { get; set; }
public string TextAnswer { get; set; }
}

所以我保存了包含答案的问卷,但现在我想检索包含问题及其答案的过滤问卷。所以我为此写了 linq,但它抛出了一个错误,我做错了什么吗?这是示例:

questionnaire = _context.Questionnaires.Include(qn => qn.Questions)
.ThenInclude(question => question.Answers.Where(a => a.UserId == userId))
.FirstOrDefault(qn => qn.Id == questionnaireId);

我得到了

Message = "The property expression 'q => {from Answer a in q.Answers where Equals([a].UserId, __userId_0) select [a]}' is not valid. The expression should represent a property access: 't => t.MyProperty'.

有什么办法解决这个问题吗?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com