title: C# - MongoDB Linq Query failing with embedded document interface
body: <p>I'm  trying to use LINQ expressions to query a simple collection in MongoDB but currently I'm facing issues when the root document contains an embedded document represented by an interface in the C# model. This is happening for me at the current MonboDB C# 2.5.0 Driver.</p>
  
  <p>I've put together an example which reproduces my problem. If I have a pair of classes defined as such:</p>
  
  <pre><code>public class MainClass
  {
      [BsonId]
      public Guid Id { get; set; }
      public String Name { get; set; }
      public InnerClass Child { get; set; }
  }
  
  public class InnerClass
  {
      public String Name { get; set; }
  }
  </code></pre>
  
  <p>I can query it with no problems with the following Linq query:</p>
  
  <pre><code>var entity = collection.AsQueryable&lt;MainClass&gt;().SingleOrDefault(x =&gt; x.Child.Name.Equals("Some Value"));
  </code></pre>
  
  <p>However, if I change my model to the following (basically replacing straight class references with interfaces):</p>
  
  <pre><code>public class MainClass : IMainClass
  {
      [BsonId]
      public Guid Id { get; set; }
      public String Name { get; set; }
      public IInnerClass Child { get; set; }
  }
  
  public class InnerClass : IInnerClass
  {
      public String Name { get; set; }
  }
  
  public interface IMainClass
  {
      Guid Id { get; set; }
      String Name { get; set; }
      IInnerClass Child { get; set; }
  }
  
  public interface IInnerClass
  {
      String Name { get; set; }
  }
  </code></pre>
  
  <p>When performing the same query I get the following exception:</p>
  
  <pre><code>System.InvalidOperationException: '{document}.Child.Name is not supported.'
  </code></pre>
  
  <p>Both examples work just fine when queried with standard mongodb queries (either with interface or concrete class in the generic signature):</p>
  
  <pre><code>var entity = collection.Find(Builders&lt;IMainClass&gt;.Filter.Eq("Child.Name", "Some Value")).SingleOrDefault();
  </code></pre>
  
  <p>Debugging around MongoDB C# Driver source code, the problem seems to happen somewhere around the PredicateTranslator class when it tries:</p>
  
  <pre><code>TryGetFieldExpression(expression, out fieldExpression)
  </code></pre>
  
  <p>For some reason, in the failing example, the Expression node arrives with a type of "System.Linq.Expressions.PropertyExpression" which fails to cast to "MongoDB.Driver.Linq.Expressions.IFieldExpression". Meanwhile, the in the working example the Expression node arrives with a type of "MongoDB.Driver.Linq.Expressions.FieldExpression" which, of course, casts just fine to "MongoDB.Driver.Linq.Expressions.IFieldExpression".</p>
  
  <p>I was also able to verify that in both examples the expression trees arrive the same at the driver but their structure start to differ at the PipelineBinder stage.</p>
  
  <p>In the end, my question is: Is this supposed to work? Is the document modeled wrong in the first place? Any suggestions on how to get this to work?</p>