lundi 8 mai 2023

How to clarify if an API returns entity with the navigation properties value populated or not

This is a rookie design question related to EF and probably other ORMs too.

Say I have an ASP.NET web page displaying information about students. A student entity has a property called teacher and a property called room, both are custom entities. In other words, in DB there'll be a student table, a teacher table, and a room table.

On this page, for each student, I need to show the teacher's name, so the teacher's value needs to be populated. (In EF, an Include(s => s.Teacher) is needed.) But I don't need to show anything about the room, so no need to populate the room property's value.

Now we need to create a LoadStudentsInfo API in the StudentService. But how should I clarify that I need some properties' value populated (this can go deeper like student.contact.address.suburb.etc), and other properties can be ignored (like room)?

I can think of 4 ways to do this:

  1. Have the info in API name (LoadStudentsInfoWithTeacher)
  2. Have parameters to include (LoadStudentsInfo(includeArg))
  3. Documentaion
  4. Create a DTO as the contract.

But none of them feels perfect to me. What is the best way to do this in your opinion?

Aucun commentaire:

Enregistrer un commentaire