0

I'm currently developing a new 3-tier REST API for our company. For this I created data object which represent the data in the database and serviceobjects which represent complex objects.

My data object is constructed like this:

public class Student
{
  public Guid StudentId {get;set;}
  public string FirstName {get;set;}
  public string LastName {get;set;}
  public int Age {get;set}
}

public class Grades
{
  public Guid GradeId {get;set;}
  public Guid StudentId {get;set;}
  public int Grade {get;set;}
}

And my service object like this:

public Class Student
{
  public Guid StudentId
  public string FirstName {get;set;}
  public string LastName {get;set;}
  public int Age {get;set;}
  public Grades {get;set;}

}

In my data layer I've created methods to get Students and get the Grades. But I'm stuck on combining the two. AFAIK this should be done in the service layer, but first getting the Students and then polulating the nested object with yet another Get from the data layer seems not the correct way.

Another way would be to have queries in the data layer that join the two together, but this defies the purpose of the datalayer as I'm returning a serviceobject.

Can somebody point me into the right direction?

Thanks in advance

Mekroebo
  • 352
  • 4
  • 11
  • This looks like it belongs more on the Software Engineering site. – Wim Ombelets Feb 28 '23 at 12:55
  • Since Grades have a StudentId there is already a connection on the data layer. There should be nothing wrong with joining them in a query. Also I would Suggest a List for the "serviceobject" since it seems there is more then one Grade for a Student. – jeb Feb 28 '23 at 15:30
  • What do you mean `combining the two`? Can you explain your problem more specifically? – Xinran Shen Mar 01 '23 at 01:21

0 Answers0