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

Linqprovider V3 IMongoCollection<T>.AsQueryable().OfType<T> does not match derived types

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 2.19.2
    • Affects Version/s: None
    • Component/s: None
    • Fully Compatible
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Summary

      When using Linqprovider V3 IMongoCollection<T>.AsQueryable().OfType<T> does not match derived types.

      Query Produced in V3

      {
          basis_dev.jobs.Aggregate([{
                      "$match": {
                          _"t": ["Entity", "Job"]
                      }
                  }, {
                      "$match": {
                          "ParentJobId": {
                              "$in": [ObjectId("6438717105606533eb0d2bfe"), ObjectId("6438717105606533eb0d2bff"), ObjectId("6438717105606533eb0d2c00"), ObjectId("6438717105606533eb0d2c01"), ObjectId("6438717105606533eb0d2c02"), ObjectId("6438717105606533eb0d2c03")]
                          }
                      }
                  }
              ])
      }

       

      Query Produced in V2

      {
          aggregate([{
                      "$match": {
                          _"t": "Job"
                      }
                  }, {
                      "$match": {
                          "ParentJobId": {
                              "$in": [ObjectId("6438717105606533eb0d2bfe"), ObjectId("6438717105606533eb0d2bff"), ObjectId("6438717105606533eb0d2c00"), ObjectId("6438717105606533eb0d2c01"), ObjectId("6438717105606533eb0d2c02"), ObjectId("6438717105606533eb0d2c03")]
                          }
                      }
                  }
              ])
      }

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      Version 2.18.0 and version 2.19.1 were tested and both result in the same query. 

      Mongo Atlas 6.0.5

      How to Reproduce

      [JsonKnownType]
      [BsonKnownType]
      public abstract class Entity

      {     [BsonId]     [JsonProperty("id")]     [BsonRepresentation(BsonType.ObjectId)]     public string Id \{ get; set; }

      }

      Entity is set as root and as KnownType

      [Table(Constants.MongoDb.CollectionNames.Jobs)]
      public abstract class Job : Entity

      {         [BsonRepresentation(BsonType.ObjectId)]     public string ParentJobId \{ get; set; }

      }

      public class SampleJob : Job

      {     public string SampleJobName \{ get; set; }

          public TimeSpan? TimeSpan { get; set; }
      }

       

      Query is 

      var parentJobIds = new List<string> { "6438717105606533eb0d2bfe" };

      IMongoCollection<Job>.AsQueryable().OfType<Job>().Where(x=> parentJobIds.Contains(x.ParentJobId));

      Additional Background

      The expected result of the query should return all derived Job types, SampleJob being one of them, but it does not. 

      This works fine in LinqProviderV2 and is preventing us from moving to V3. 

            Assignee:
            oleksandr.poliakov@mongodb.com Oleksandr Poliakov
            Reporter:
            dferrante@darlingconsulting.com David Ferrante
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: