title: Mongodb - how to deserialze when a property has an Interface return type
body: <p>I'm attempting to avoid introducing any dependencies between my Data layer and client code that makes use of this layer, but am running into some problems when attempting to do this with Mongo (using the MongoRepository)</p>
  
  <p>MongoRepository shows examples where you create Types that reflect your data structure, and inherit Entity where required. Eg.</p>
  
  <pre><code>[CollectionName("track")]
  public class Track : Entity  
  {
      public string name { get; set; }
      public string hash { get; set; }
  
      public Artist artist { get; set; }
      public List&lt;Publish&gt; published {get; set;}
      public List&lt;Occurence&gt; occurence  {get; set;}
  }
  </code></pre>
  
  <p>In order to make use of these in my client code, I'd like to replace the Mongo-specific types with Interfaces, e.g:</p>
  
  <pre><code>[CollectionName("track")]
  public class Track : Entity, ITrackEntity 
  {
      public string name { get; set; }
      public string hash { get; set; }
  
      public IArtistEntity artist { get; set; }
      public List&lt;IPublishEntity&gt; published {get; set;}
      public List&lt;IOccurenceEntity&gt; occurence  {get; set;}
  }
  </code></pre>
  
  <p>However, the Mongo driver doesn't know how to treat these interfaces, and I understandably get the following error:</p>
  
  <p><strong>An error occurred while deserializing the artist property of class sf.data.mongodb.entities.Track: No serializer found for type sf.data.IArtistEntity. ---> MongoDB.Bson.BsonSerializationException: No serializer found for type sf.data.IArtistEntity.</strong></p>
  
  <p>Does anyone have any suggestions about how I should approach this?</p>