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

Using abstract type within Queryable Linq statement

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 2.2.4
    • 2.2.2
    • Linq
    • Fully Compatible

    Description

      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
      

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: