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

GraphLookup cannot connect one-to-many

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.11.0
    • Affects Version/s: 2.9.1
    • Component/s: Linq
    • None

      I'm trying to do a graph lookup, but it looks like the C# API doesn't agree with my thinking here:

      class Node
      {
          string Id { get; set; }
          List<string> ParentIds { get; set; }
      }
      
      class NodeWithChildren
      {
          Node[] Children { get; set; }
      }
      
      var query = collection.Aggregate()
           .GraphLookup(
                from: collection,
                connectFromField: x => x.Id,
                connectToField: x => x.ParentIds,
                startWith: x => x.Id,
                @as: (NodeWithChildren x) => x.Children);
      

      This throws:

       
      ArgumentException:  TConnectFrom must be either TConnectTo or a type that implements IEnumerable<TConnectTo>.
      Parameter name: TConnectFrom
      

      While the query should work fine:

       db.Node.aggregate([
           { $graphLookup: { from: 'Node', startWith: "$_id", connectFromField: "_id", connectToField: "ParentIds", as: "Children" } }
      ])
      

            Assignee:
            mikalai.mazurenka@mongodb.com Mikalai Mazurenka (Inactive)
            Reporter:
            bhaarsma@cloudbilling.nl Bouke Haarsma
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: