Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1542

Using abstract type within Queryable Linq statement

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.2.4
    • Affects Version/s: 2.2.2
    • Component/s: Linq
    • Fully Compatible

      When querying against a property that is defined as an abstract base type the driver fails to handle a cast to a concrete type within the where clause.

      The following example worked within the 1.92 of the C# driver.

      Below is an example:

      public class Entity
      {
       public A Result { get; set; }
      }
      
      [BsonKnownTypes(new Type[] { typeof(B), typeof(C)})]
      public abstract class A
      {
       public string Id { get; set; }
      }
      
      public class B : A
      {
       public string PropertyOnB { get; set; }
      }
      
      public class C : A
      {
       public string PropertyOnC { get; set; }
      }
      

      Query:

      collection.AsQueryable().Where(q => ((B)q.Result).PropertyOnB == "TestResult").ToList();
      
      Executing this query gives the following exception:
      
      Convert({document}{Results}).PropertyOnB is not supported
      

            Assignee:
            craig.wilson@mongodb.com Craig Wilson
            Reporter:
            stephencbond@gmail.com Stephen Bond
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: