title: C# unit of work bad implementation
body: <p>I tried to implement a Unit of Work with SQLCE database.
  Everything works correctly except for one thing.</p>
  
  <p>I have a scenario where a patient can perform different sessions and each session is based on a specific Test. these are the implementations:</p>
  
  <pre><code>public class Patient
  {
      public int Id { get; set; }
      public byte[] IdentificationCode { get; set; }
      public string Sex { get; set; }
  
      public virtual List&lt;Session&gt; Sessions { get; set; }        
  }
  
  public class Session
  {
      public int Id { get; set; }
  
      public Guid Unique { get; set; }
      public DateTime DateTime { get; set; }
  
      public virtual Patient Patient { get; set; }
      public virtual Test Test { get; set; }
  
      public virtual List&lt;VideoExerciseResult&gt; VideoSessionResults { get; set; }
      public virtual List&lt;AudioExerciseResult&gt; AudioSessionResults { get; set; }
  }
  
  public class Test
  {
      public int Id { get; set; }
      public string Name { get; set; }
  
      public virtual List&lt;Session&gt; Sessions { get; set; }
  }
  </code></pre>
  
  <p>When i perform a Test the data are actually saved and i can directly go to see the results for a session.</p>
  
  <p>But when i Run again the application and load the session the Results and the Test in the Session appear as null (while Patient, Id and Unique have correct values).</p>
  
  <pre><code>private void GetSessionData()
      {
          // List&lt;Test&gt; tempList = new List&lt;Test&gt;(UOW.Tests.GetAll());
          // List&lt;AudioExerciseResult&gt; tempList1 = new List&lt;AudioExerciseResult&gt;(UOW.AudioSessionsResults.GetAll());
  
          switch (SelectedSession.Test.Name)
          {
  </code></pre>
  
  <p>And I discovered that loading the list of Tests and Results for the database before calling the Session object will make the values of Test and Results inside the Session object correctly appear.</p>
  
  <p>There is obviously something that i don't understand in the world of DB. Can someone clarify me why i have to load the list of values from the db?</p>
  
  <p>Is I wasn't clear I will explain more precisely...</p>