In a .NET application, I am trying to construct a DTO on the repo layer as following. However, I have a nasty async function deep down in the statement. How should I chain the async calls?
var subtopics; // I have a subtopics array
var topicModel = new TopicModel
{
Id = 0,
SubtopicModels = subtopics
.Select(subtopic => new SubtopicModel
{
Id = 0,
VideoModels = subtopic.Videos // simple await on this line doesn't work
.OrderBy(video => video.OrderInSubtopic)
.Select(async video => new VideoModel
{
Id = 0,
VideoLeftAtSeconds = (await _db.VideoActivities
.FirstOrDefaultAsync(activity => activity.UserId == userId && activity.VideoId == videoId))
.LeftAtSeconds
}).ToList()
}).ToList(),
};