title: Selecting a new type from linq query
body: <p>I'm trying to transform some data selected out of a repository using Linq.</p>
  
  <p>My code so far:</p>
  
  <pre><code>Repository&lt;Result&gt; _repository = new Repository&lt;Result&gt;();
  
  var disciplines = _repository.Query()
      .Select(d =&gt; new Discipline
      {
          DisciplineCode = d.DisciplineCode,
          Name = d.DisciplineName
      })
      .Distinct()
      .ToList();
  </code></pre>
  
  <p>Result class looks like:</p>
  
  <pre><code>public class Result
  {
      public virtual int ResultId { get; set; }
      public virtual string DisciplineCode { get; set; }
      public virtual string DisciplineName { get; set; }
      public virtual int CompetitorId { get; set; }
      //other stuff
  }
  </code></pre>
  
  <p>When this runs, I get </p>
  
  <blockquote>
    <p>Unable to determine the serialization information for the expression:
    &lt; MemberInitExpression ></p>
  </blockquote>
  
  <p>Any idea what's going wrong?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>As per Chris suggestion, I tried the Select after ToList like this:</p>
  
  <pre><code>var disciplines = _repository.Query()
                  .Select(d =&gt; new
                  {
                      DisciplineCode = d.DisciplineCode,
                      Name = d.DisciplineName
                  })
                  .Distinct()
                  .ToList()
                  .Select(d =&gt; new Discipline { DisciplineCode = d.DisciplineCode, Name = d.Name });
  </code></pre>
  
  <p>However, this time, similar error, but it's to do with the anonymous type:</p>
  
  <blockquote>
    <p>Unable to determine the serialization information for the expression: new __AnonymousType(d.DisciplineCode, d.DisciplineName).</p>
  </blockquote>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>To clarify, .Query is returning IQueryable<br>
  The underlying database is MongoDB (using C# driver)</p>
  
  <p>If I do this: </p>
  
  <pre><code>var disciplines = _repository.Query()
      .Select(d =&gt; d.DisciplineName)
      .Distinct()
      .ToList()
  </code></pre>
  
  <p>It works. By works, I mean I get a <code>distinct</code> list of DisciplineNames</p>
  
  <p>I need to be able to select more properties than just the name however.</p>