Я новичок в Entity Framework Core, в моем коде есть несколько объектов класса Questions
и список вариантов ответов на эти вопросы. Мой список запросов Choices
всегда возвращает Null.
Вот мои занятия:
public class Questions
{
[Key]
public int QuestionID { get; set; }
public string Question { get; set; }
public ICollection<Choices> choices { get; set; }
}
public class Choices
{
[Key]
public int ChoicesId { get; set; }
public int QuestionId { get; set; }
public Questions questions { get; set; }
public string Choice { get; set; }
}
public class SqlUserRepository : IUserRepository
{
private readonly AppDbContext context;
public SqlUserRepository(AppDbContext context)
{
this.context = context;
}
public List<Questions> getAllQuestions()
{
return context.questions.ToList();
}
}
Я получаю это O / p. выбор всегда возвращает нуль
[
{ "questionID":1, "question":"which is your fav.heroien", "choices":null },
{ "questionID":2, "question":"which is your fav.hero", "choices":null }
]
Я ожидаю этот вывод
[{"questionID":1,"question":"which is your fav.heroien","choices":[{"choicesId":5,"questionId":1,"questions":null,"choice":"kajol Agarwal"},{"choicesId":6,"questionId":1,"questions":null,"choice":"Thammanna Bhatia"},{"choicesId":7,"questionId":1,"questions":null,"choice":"Anushka Shetty"},{"choicesId":8,"questionId":1,"questions":null,"choice":"Keerthi Suresh"}]},{"questionID":2,"question":"which is your fav.hero","choices":[{"choicesId":1,"questionId":2,"questions":null,"choice":"upendera"},{"choicesId":2,"questionId":2,"questions":null,"choice":"real star"},{"choicesId":3,"questionId":2,"questions":null,"choice":"Super star"},{"choicesId":4,"questionId":2,"questions":null,"choice":"Only star"}]}]