title: How do you use BsonClassMap to map a POCO domain object property as a manual or DBRef reference?
body: <p>Using BsonClassMap, is it possible to map a domain object reference while keeping the domain object assembly persistent ignorant (changing the <code>public A Reference { get; set; }</code> property to <code>public MongoDBRef Reference{ get; set; }</code> in the sample class <code>B</code> below is not acceptable).  </p>
  
  <p>For this case, the referenced object is not a part of the same aggregate, and should not be stored as a nested document.</p>
  
  <p>Is it possible map two domain objects in a relationship like this:</p>
  
  <pre><code>public class A
  {
      public Guid Id {get; private set; }
  }
  
  public class B
  {
      public Guid Id { get; private set; }
      public A Reference { get; set; }
  }
  </code></pre>
  
  <p>Into the following document structure:</p>
  
  <pre><code>// Collection for class A
  { _id: "11111111-1111-1111-1111-111111111111" }
  
  // Collection class B
  { 
      _id: "22222222-2222-2222-2222-222222222222",
      reference_id: "11111111-1111-1111-1111-111111111111"
  }
  </code></pre>
  
  <p>The mapping may look like:</p>
  
  <pre><code>BsonClassMap.RegisterClassMap&lt;A&gt;(cm =&gt; 
  {
      cm.MapIdProperty(c =&gt; c.Id)
          .SetIdGenerator(new GuidGenerator())
          .SetRepresentation(BsonType.String);
  }
  
  BsonClassMap.RegisterClassMap&lt;B&gt;(cm =&gt; 
  {
      cm.MapIdProperty(c =&gt; c.Id)
          .SetIdGenerator(new GuidGenerator())
          .SetRepresentation(BsonType.String);
  
      // How do I map the B.Reference to a manual reference (like 
      // the sample doc structure above) or possibly as a DBRef?
  }
  </code></pre>
  
  <p>So, without changing the model, how do I map the <code>Reference</code> property to object <code>A</code>, from object <code>B</code> as either a DBRef or as a manual references (as in my sample document structure above)?</p>
  
  <p>Is this possible using BsonClassMap?  Or in order to use BsonClassMap and keep my domain assembly persistent ignorant, do I need to change the model to something like:</p>
  
  <pre><code>public class A
  {
      public Guid Id {get; private set; }
  }
  
  public class B
  {
      public Guid Id { get; private set; }
      public Guid ReferenceId { get; set; } // Don't reference the object directly,
                                            // just store the Guid to the 
                                            // referenced object.
  }
  </code></pre>