I am modeling the Student and Attendance functionality using DDD aggregates. What I ended up was Student class having a list of Attendance records. I am using EF core to load the student along with all the attendances associated to the student.
So every day there will a attendance record registered against a student. The attendance record can be updated multiple times through out the day. I ended up creating a public method on the Student class called CreateOrUpdateAttendance(Date date, AttendanceDetails attendance) which would internally check if there are any attendance record for the given date if not create a new attendance instance, update this attendance record with the provided attendance details add/ update list of attendance associated to the student. So every time there is a attendance updated/ created for a student the student entity is queried from the data base along with all attendance records. Student is queried based on the Id received from input to check whether the provided Id is valid or not.
The problem is as days go by there would be many attendance records associated to the student which means unnecessary pulling of all attendance records associated to the student which will lead to poor query performance.
Is Student the proper root here? Unfortunately EF core doesn't support filtering child objects yet.
My question is how to deal the use case where the child entities needs to be updated inside an aggregate More specifically a single entity of the list of entities inside an aggregate?
In this case should I treat the Attendance as different aggregate? So that I can query the attendance record independent of the student record?
I ended up making two calls to database one to check the student(with out loading the attendance) and other to fetch the attendance record.
I am missing something here? Should I rethink my design? Any guidance would be really helpful.
Aucun commentaire:
Enregistrer un commentaire