i have a class like this
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; }
}
and a Question class like this
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; }
}
i want to write a query to select a survey which contains a particular question
something along these lines
Survey s1 = db.Surveys.Where(s => s.Questions.Where(q => q.QuestionId == "1eb56610-853d-4a9e-adc7-e0ec069390b7"));
Survey s1 = db.Surveys
.Where(s => s.Questions.Any(q => q.QuestionId == "1eb56610-853d-4a9e-adc7-e0ec069390b7"))
.FirstOrDefault();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With