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
}
Entity is set as root and as KnownType
[Table(Constants.MongoDb.CollectionNames.Jobs)]
public abstract class Job : Entity
}
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.