I am using Entity Framework and I would like to find out how to get data from a class and a child of the class. Here is my setup:
public class Question
{
public Question()
{
this.Answers = new List<Answer>();
}
public int QuestionId { get; set; }
...
...
public string Title { get; set; }
public virtual ICollection<Answer> Answers { get; set; }
}
public class Answer
{
public int AnswerId { get; set; }
public string Text { get; set; }
public int QuestionId { get; set; }
public virtual Question Question { get; set; }
}
I have set the following as I don't want Lazyloading for all the other classes:
DbContext.Configuration.LazyLoadingEnabled = false;
Here is the code I am currently using:
public IList<Question> GetQuestions(int subTopicId, int questionStatusId)
{
var questions = _questionsRepository.GetAll()
.Where(a => a.SubTopicId == subTopicId &&
a.QuestionStatusId == questionStatusId)
.ToList();
return questions;
}
My repository looks like this:
public virtual IQueryable<T> GetAll()
{
return DbSet;
}