Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2878

Aggregate Project with object and Id

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: 2.10.0
    • Fix Version/s: None
    • Component/s: Linq, Serialization
    • Labels:
      None
    • Environment:
      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();
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            klaus.pruenster@gmail.com Klaus Prünster
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: