title: Querying into a complex object with Dapper
body: <p>I have a Customer class with the following properties:</p>
  
  <pre><code>public int Id { get; set; }
  public string Name { get; set; }
  public int AddressId { get; set; }
  public Address Address { get; set; }
  </code></pre>
  
  <p>My goal is to write a Dapper query that will use an Inner Join to populate the entire Address property within each Customer that is returned.</p>
  
  <p><strong>Here is what I have and it is working but I am wondering if this is the cleanest/simplest way to do it:</strong></p>
  
  <pre><code>StringBuilder sql = new StringBuilder();
  using (var conn = GetOpenConnection())
  {
      sql.AppendLine("SELECT c.Id, c.Name, c.AddressId, a.Address1, a.Address2, a.City, a.State, a.ZipCode ");
      sql.AppendLine("FROM Customer c ");
      sql.AppendLine("INNER JOIN Address a ON c.AddressId = a.Id ");
  
      return conn.Query&lt;Customer, Address, Customer&gt;(
          sql.ToString(),
          (customer, address) =&gt; {
              customer.Address= address;
              return userRole;
          },
          splitOn: "AddressId"
      ).ToList();
  }
  </code></pre>
  
  <p>I have some concern about adding another property such as:</p>
  
  <pre><code>public Contact Contact { get; set; }
  </code></pre>
  
  <p>I am not sure how I would switch the syntax above to populate both Address and Contact.</p>