title: MongoDB C# Driver - Return an Id of type string from controller
body: <p>I have the following model:  </p>
  
  <pre><code>public class Student
  {
      public ObjectId Id { get; set; }
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>And the this endpoint in my controller: </p>
  
  <pre><code>public IEnumerable&lt;Student&gt; GetAll()
  {
      MongoCollection&lt;Student&gt; collection = Db.GetCollection&lt;Student&gt;("students");
      List&lt;Student&gt; students = collection.AsQueryable().ToList();
      return students;
  } 
  </code></pre>
  
  <p>The GetAll() endpoint which is exposed to the public, returns a Student which has an Id of type ObjectId, which is not a standart type. I would rather want it to be of type string.  </p>
  
  <p>But if I change it to string, I can't use the .ToList(), getting an error like so:<br>
  <strong>"Cannot deserialize string from BsonType ObjectId"</strong></p>
  
  <p>I know I can solve this using some projections and conversions, but they will add some ugly and noisy code to the CRUD methods.  </p>
  
  <p>What is the best way to keep <strong>Id in string type</strong> exposed to the public and still be able to use the c# driver's api?</p>