locked
Should a DAO method work with domain model or a DTO? RRS feed

  • Question

  • Hi all,

    I am writing DAO methods for Data Access Layer and was wondering should they return a DTO or a domain model.

    For example I have 2 domain models Project and Employee. Project has array of Employee.

    class Project
    {
       public long ProjectId;
       public string ProjectName;
       public Employee[] Employees;
    }
    
    class Employee
    {
       public long EmployeeId;
       public string[] ProjectNotes;
    }
    

    On one screen I have to show a project's name and all the notes which any employee has entered for that project group by employee. So I was thinking that my Presentation Layer needs a DTO ProjectNotePresentationDTO:

    class ProjectNotePresentationDTO
    {
      public long ProjectId;
      public string ProjectName;
      public Dictionary<long,string[]> EmployeeNotes; 
      // key of this dictionary is EmployeeId and value is ProjectNotes
    }
    

    Suppose DAO method returns a DTO ProjectNoteDTO:

    class ProjectNoteDTO
    {
      public long ProjectId;
      public string ProjectName;
      public long EmployeeId;
      public string[] Notes;
    }

    Assuming that the communication is Presentation Layer <--> Business Layer <--> Data Access Layer, I think I have 2 options:

    1) The Data Access Layer returns ProjectNoteDTO, the Business Layer converts it into domain model Project (with its property Employees populated), and then pass it to Presentation Layer which converts it into ProjectNotePresentationDTO.

    2) The Data Access Layer method returns domain model Project (with its property Employees populated), the Business Layer then pass it to Presentation Layer which converts it into ProjectNotePresentationDTO.

    Which one makes sense and why?

    Thanks


    Monday, August 26, 2013 9:28 PM