title: Efficient Way To Query Nested Data
body: <p>I have need to select a number of 'master' rows from a table, also returning for each result a number of detail rows from another table. What is a good way of achieving this without multiple queries (one for the master rows and one per result to get the detail rows).</p>
  
  <p>For example, with a database structure like below:</p>
  
  <pre><code>MasterTable:
      - MasterId BIGINT
      - Name NVARCHAR(100)
  
  DetailTable:
      - DetailId BIGINT
      - MasterId BIGINT
      - Amount MONEY
  </code></pre>
  
  <p>How would I most efficiently populate the <code>data</code> object below?</p>
  
  <pre><code>IList&lt;MasterDetail&gt; data;
  
  public class Master
  {
      private readonly List&lt;Detail&gt; _details = new List&lt;Detail&gt;();
  
      public long MasterId
      {
          get; set;
      }
  
      public string Name
      {
          get; set;
      }
  
      public IList&lt;Detail&gt; Details
      {
          get
          {
              return _details;
          }
      }
  }
  
  public class Detail
  {
      public long DetailId
      {
          get; set;
      }
  
      public decimal Amount
      {
          get; set;
      }
  }
  </code></pre>