实体框架中的嵌套 where 查询

tah*_*ala 5 linq entity-framework

我有一堂这样的课

public class Survey
    {
        public Survey()
        {
            SurveyResponses=new List<SurveyResponse>();
        }

        public Guid SurveyId { get; set; }

        public string SurveyName { get; set; }

        public string SurveyDescription { get; set; }

        public virtual ICollection<Question> Questions { get; set; }

        public virtual ICollection<SurveyResponse> SurveyResponses { get; set; }
    }
Run Code Online (Sandbox Code Playgroud)

和这样的问题类

 public class Question
    {

        public Guid QuestionId { get; set; }

        public string QuestionText { get; set; }

        public QuestionType QuestionType { get; set; }

        public virtual ICollection<Option> Options { get; set; }

        public bool IsOtherAllowed { get; set; }

        public virtual ICollection<Answer> Answers { get; set; }

    }
Run Code Online (Sandbox Code Playgroud)

我想写一个查询来选择包含特定问题的调查

沿着这些路线的东西

 Survey s1 = db.Surveys.Where(s => s.Questions.Where(q => q.QuestionId == "1eb56610-853d-4a9e-adc7-e0ec069390b7"));
Run Code Online (Sandbox Code Playgroud)

Fab*_*ano 6

Survey s1 = db.Surveys
    .Where(s => s.Questions.Any(q => q.QuestionId == "1eb56610-853d-4a9e-adc7-e0ec069390b7"))
    .FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)