title: POCO - Flatten or Use Complex Types
body: <p>I am using POCOs as my model classes in a ASP.Net MVC project. So far this is working well, but in most cases these POCOs contain simple types. I now have a situation where I am considering using some complex types and I am not sure about the benefits of this approach. Further my situation is complicated by the fact that I need to split a single database table into multiple POCOs. The following example will explain. I have an employee table with about 40 fields. I don't want to always be passing around this large object with all its properties so I created 3 POCO classes that represent logical groupings of the data as follows: </p>
  
  <pre><code>public class EmployeeProfile
  {
      public int EmployeeID { get; set; }
      public string FirstName { get; set; }        
      public string LastName { get; set; }
      public string Gender { get; set; }
      etc ...    
  }
  
  public class EmployeeContact
  {
      public Address Address { get; set; }
      public PhoneNumber Phone { get; set; }        
      public string Email { get; set; }
  }
  
  public class EmploymentInfo
  {
      public decimal Salary { get; set; }       
      public string Occupation { get; set; }
      etc ....
  }
  </code></pre>
  
  <p>So far so good, however I also at times do need the entire employee table as a single object and that is where I am unsure. I could create the employee class by putting the other types in it like so:</p>
  
  <pre><code>public class EmployeeDetail
  {
      public EmployeeProfile EmployeeProfile { get; set; }
      public EmployeeContact EmployeeContact { get; set; }
      public EmploymentInfo EmploymentInfo { get; set; }        
  
  }
  </code></pre>
  
  <p>or I could copy all the properties individual properties of the three POCOs including the complex types contained therein into the EmployeeDetail class so that it is flat, with simple properties like so:</p>
  
  <pre><code>public class EmployeeDetail
  {
      public int EmployeeID { get; set; }
      public string FirstName { get; set; }        
      public string LastName { get; set; }
      public string Gender { get; set; }
      etc ...        
      public Address Address { get; set; }
      public PhoneNumber Phone { get; set; }        
      public string Email { get; set; }
      public decimal Salary { get; set; }       
      public string Occupation { get; set; }
      etc ....
  
  }
  </code></pre>
  
  <p>aside from the fact that the version containing complex types will take a shorter time to create the POCO, what are the benefits of using one approach over another? I get the idea that the whole point is to be object oriented, but I'm not sure if in this case there is any benefit to "nesting" these objects. It seems to me like there will be more work accessing the nested objects and translating them back and forth between my view model and domain model. </p>
  
  <p><strong>Edit:</strong> I would like to point out that the sub-models I am considering are not specific to a particular view. They are likely to be used multiple places throughout the application. This is an HR/Employee Benefits app. I need these classes to be reusable otherwise I would just put them in a ViewModel, which I am already using.</p>