return queryable
.Include(x => x.LessonState)
.Select(x => new
{
Entity = x,
Phases = x.Phases.Select(p => new
{
Phase = p,
LastUserAnswer = p.UserAnswers.OrderByDescending(ua => ua.Id).FirstOrDefault()
})
})
.ToList()
.Select(x => new YourEntity
{
// Map other properties from x.Entity to the new YourEntity object
LessonState = x.Entity.LessonState,
Phases = x.Phases.Select(p => new YourPhaseClass
{
// Map other properties from p.Phase to the new YourPhaseClass object
UserAnswer = p.LastUserAnswer
}).ToList()
})
.AsQueryable();
return queryable
.Include(x => x.LessonState)
.Select(x => new
{
Entity = x,
Phases = x.Phases.Select(p => new
{
Phase = p,
LastUserAnswer = p.UserAnswers.OrderByDescending(ua => ua.Id).FirstOrDefault()
})
})
.ToList()
.Select(x => new YourEntity
{
// Map other properties from x.Entity to the new YourEntity object
LessonState = x.Entity.LessonState,
Phases = x.Phases.Select(p => new YourPhaseClass
{
// Map other properties from p.Phase to the new YourPhaseClass object
UserAnswer = p.LastUserAnswer
}).ToList()
})
.AsQueryable();