I am having a hard time figuring this out. The examples out there are not using async calls.
How do I use Include
when making a get call for a single object by id?
Do I need to get rid of the async call? I need to include the matching
ExerciseRepetitions && ExerciseImages
Also how could I add a
.Where(k => k.IsHidden != true)
for each child model?
[Route("")]
public IQueryable<Exercise> GetExercises()
{
var result = db.Exercises
.Include(c => c.ExerciseRepetitions)
.Include(o => o.ExerciseImages)
.Where(k => k.IsHidden != true);
return result;
}
// GET: api/Exercises/5
[Route("{id:int}")]
[ResponseType(typeof(Exercise))]
public async Task<IHttpActionResult> GetExercise(int id)
{
Exercise exercise = await db.Exercises.FindAsync(id);
///// I need this call to return ExerciseRepetitions && ExerciseImages as nested arrays. Also I need to filter out any object that has IsHidden = true.
if (exercise == null)
{
return NotFound();
}
return Ok(exercise);
}