Details
-
Bug
-
Status: Closed
-
Major - P3
-
Resolution: Fixed
-
2.10.0
-
None
-
MongoDb on Cent Os 8 with C# 8 .net core 3.0
Description
Aggregation with Project and anonymous type works
var j = _context.GetCollection<CustomerArticles>("Worked_CustomersArticles") .Aggregate() .Project(c => new { Id = c.Id, Articles = c.Articles.Where(c => c.Code == "12") }) .Limit(5) .ToList(); |
Aggregation with Project and strongly typed class does not work
var j = _context.GetCollection<CustomerArticles>("Worked_CustomersArticles")var j = _context.GetCollection<CustomerArticles>("Worked_CustomersArticles") .Aggregate() .Project(c => new CustomerArticles { Id = c.Id, Articles = c.Articles.Where(c => c.Code == "12") }) .Limit(5) .ToList(); |
Exception:
System.FormatException: 'Element 'Id' does not match any field or property of class QueryTester.CustomerArticles.'
But I found a workaround:
var j = _context.GetCollection<CustomerArticles>("Worked_CustomersArticles") var j = _context.GetCollection<CustomerArticles>("Worked_CustomersArticles") .Aggregate() .Project(c => new { Id = c.Id, Articles = c.Articles.Where(c => c.Code == "12") }) .Project(c => new CustomerArticles { Id = c.Id, Articles = c.Articles.Where(c => c.Code == "12") }) .Limit(5) .ToList(); |