title: Deserialising polymorphic types with MongoDB C# Driver
body: <p>Assume, I have a base class</p>
  
  <pre><code>public class Node{
      public ObjectId Id;
      public String nodeName;
      public ObjectId parentNode;
  }
  </code></pre>
  
  <p>and 2 derived classes</p>
  
  <pre><code>public class PlotNode:Node{
      public ObjectId Id;
      public String plotDetail;
  }
  
  public class EndNode:Node{
      public ObjectId Id;
      public int resultCode;
  }
  </code></pre>
  
  <p>Several objects of all 3 classes are serialized are in database.</p>
  
  <p>And only data i have is a list of ObjectId's, and only thing known about these ids is that they are certain to be Node ids but it's not know whether they are Node,PlotNode or EndNode in deserialise time.</p>
  
  <p>I am using this to deserialize:</p>
  
  <pre><code>var collection = db.GetCollection&lt;Node&gt;("nodes");
  var query = Query&lt;Node&gt;.EQ(e =&gt; e.Id, id);
  Node node = collection.FindOne(query);
  </code></pre>
  
  <p>And in the end i get Nodes, not actual PlotNodes or EndNodes.</p>
  
  <p>How can i know if they are one of the derived types and get back a object of that type?</p>