Aggregate Project with object and Id

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major - P3
    • 2.14.0
    • Affects Version/s: 2.10.0
    • Component/s: LINQ, Serialization
    • None
    • Environment:
      MongoDb on Cent Os 8 with C# 8 .net core 3.0
    • None
    • None
    • None
    • None
    • None
    • None

      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();
      

              Assignee:
              Unassigned
              Reporter:
              Klaus Prünster
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Created:
                Updated:
                Resolved: