❔ Advice on Data modeling-ef core

Basically I've got a lesson which is an aggregate root, On said lesson i got phases and each phase has an answer.
I want to be able to save past answers aswell to analyze.
Current Code:
      return queryable
                
                .Include(x => x.LessonState)
                .Include(x=>x.Phases).ThenInclude(x=>x.UserAnswer);
        }

So I've come up with 2 approaches:
1.A phase will contain a list of answers and we will only load the last added to the db when making calls, Was unsure how to do it and Chat-gpt gave me this:

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();

2.create a new entity named pastAnswer that sits on Phase, but doesnt load it except for when we want to load it for something
And when the user submits a new answer, it gets saved as a past answer, and the new answer becomes the user answer
Was this page helpful?