Details
-
Bug
-
Resolution: Works as Designed
-
Unknown
-
None
-
2.18.0
-
None
Description
I'm trying to using an aggregation projection stage to convert input documents to output documents with calculated properties. Using a C# expression with a definite type, e.g.
var projection = Builders<TaskEntity>.Projection
|
.Expression(e => new TaskHeader |
{
|
Id = e.Id,
|
Name = e.Name,
|
LinkCount = e.Links.Length
|
});
|
results in
System.FormatException: Element 'Links' does not match any field or property of class TaskHeader.
|
whereas defining the projection step using a BsonDocument as below works as expected
var projection = new BsonDocumentProjectionDefinition<TaskEntity, TaskHeader>( |
BsonDocument.Parse(@"{
|
Name: 1, |
LinkCount: { $size: ""$Links"" } |
}"));
|
Is there some way to build valid typed projections via C# expression tree when the output property names don't match the input property names? I thought this may have been fixed by the V3 Linq provider but that seems to give the same exception.