title: .Net MongoDB Driver Subcollection, Builders, and Projections
body: <p>(Forgive my newbiness.) If given the following classes how would you </p>
  
  <ol>
  <li>Query on a property of a subcollection. (Avoiding strings as much as possible)</li>
  <li>Project and map the result to the given DTO?</li>
  </ol>
  
  <p>Classes:</p>
  
  <pre><code>public class Customer{
  
      public ObjectId Id;
      public string FirstName;
      public string LastName;
      .
      .   
      . (Other Properties specific to the customer profile)
      public IEnumerable&lt;Transaction&gt; Transactions;
  }
  
  public class Transaction{
      public ObjectId ItemId;
      public DateTime PurchaseDate;
      .
      .
      . (etc.)
  }
  
  public class TransactionDTO{
      public ObjectId CustomerId;
      public string FirstName;
      public ObjectId ItemId;
      public DateTime PurchaseDate; 
  }
  </code></pre>
  
  <p>Aside from any compile issues there might be, is this the wrong/right approach to mongo?</p>
  
  <p>How would I get a list of transactions where ItemId == x projected to the TransactionDTO using the Builders class provided in the mongo Driver.</p>
  
  <p>This is where I'm headed but I've run into some road blocks.</p>
  
  <p>to query the main collection (Customer) on a specific property you can build the query like this:</p>
  
  <pre><code>Builders&lt;Customer&gt;.Filter.Eq(c=&gt;c.firstname,"Bob");
  </code></pre>
  
  <p>but using this syntax I can't query on the subcollection.</p>
  
  <pre><code>Builders&lt;Customer&gt;.Filter.Eq(c=&gt;c.Transactions....????, "match condition");
  </code></pre>
  
  <p>so what is the proper way to be able to query? Similarly the projection would look something like this:</p>
  
  <pre><code>Builders&lt;Customer&gt;.Projection.Expression(c=&gt; new TransactionDTO(){
      CustomerId = x.Id,
      FirstName = x.FirstName, // &lt;- these should be fine.
      itemId = x.Transaction...???
      PurchaseDate = x.Transaction....???
  })
  </code></pre>
  
  <p><a href="http://mongodb.github.io/mongo-csharp-driver/2.0/reference/driver/definitions/" rel="nofollow">Mongo C# Docs</a></p>