I got a Problem with my API. I want to get a random amout of questions back.
The Model of my question has a list of answers and hints:
public class Question
{
public int Id { get; set; }
public string Text { get; set; }
public string Explanation { get; set; }
public Category Category { get; set; }
public ICollection<Answer> Answers { get; set; }
public ICollection<Hint> Hints { get; set; }
}
normally if i call my get method i get a json with all the lists back
return _ctx.Questions.Include(x => x.Answers).Include(x => x.Hints).ToList();
{
"id": 1,
"text": "Test?",
"explanation": "Test",
"category": null,
"answers": [
{
"id": 1,
"text": "Test",
"isCorrect": true
},
{
"id": 2,
"text": "Test1",
"isCorrect": false
},
{
"id": 3,
"text": "Test2",
"isCorrect": false
},
{
"id": 4,
"text": "Test3",
"isCorrect": false
}
],
"hints": [
{
"id": 1,
"text": "..."
},
{
"id": 2,
"text": "..."
}
]
}
But if I want to get random picks with a orderby i only got empty lists
return _ctx.Questions.Include(x => x.Answers).Include(x => x.Hints).OrderBy(o => Guid.NewGuid()).Take(amount).ToList();
{
"id": 1,
"text": "test",
"explanation": "..-",
"category": null,
"answers": [],
"hints": []
}
Does someone have a Idea to fix this?