Summary
Projecting to a POCO using constructor that is inheriting from a base POCO fails to project using the LinqProvider V3 but works fine using the LinqProvider V2.
Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).
driver: 2.19.1
How to Reproduce
Test code:
public class InheritanceTest { [Fact] public async Task Test() { BsonDefaults.GuidRepresentationMode = GuidRepresentationMode.V3; BsonSerializer.RegisterSerializer(new GuidSerializer(GuidRepresentation.Standard)); var mongoClient = new MongoClient(MongoClientSettings.FromConnectionString("mongodb://intigriti:!ntIgrit!@localhost:27017/?replicaSet=rs1")); var database = mongoClient.GetDatabase("testdatabase"); var collection = database.GetCollection<TestDocument>("testdocuments"); var id = Guid.NewGuid(); await collection.InsertOneAsync(new TestDocument { Id = id, Name = "test" }); var dto = await collection .Find(x => x.Id == id) .Project(x => new ChildTestDto(x.Id, x.Name)) .FirstAsync(); } public class TestDocument { public Guid Id { get; set; } public string Name { get; set; } } public class ParentTestDto { public Guid Id { get; set; } public string Name { get; set; } public ParentTestDto(Guid id, string name) { Id = id; Name = name; } } public class ChildTestDto : ParentTestDto { public ChildTestDto(Guid id, string name) : base(id, name) { } } }
Additional Background
We are trying to upgrade to the latest driver version but are hitting multiple roadblocks. It feels like the LinqProvider V3 isn't production ready. Documentation with some guidelines for migration would be a nice addition. Like the V2 provider has a fall-back to in memory projection when the expression isn't supported while V3 just crashes hard.
- has to be done after
-
CSHARP-4656 Simplify A : "$A" to A : 1 only on find
- Closed
-
CSHARP-4550 NewExpression and MemberInitExpression behaviour differs
- Closed