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

LINQ SelectMany operator on Dictionary

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Unresolved
    • Icon: Minor - P4 Minor - P4
    • None
    • 2.4.2
    • Linq

    Description

      I'm attempting to use the new 2.4.2 LINQ features in the aggregation pipeline, but my data structures use a lot of dictionaries that need to be unwound. It looks like the driver does not support $unwind generation for dictionaries. Aggregation stage {$unwind : "$TestDictionary" } words wonders in the shell, but calling the query.ToString() function below throws a System.NotSupportedException:

      The collection selector's serializer must implement IBsonArraySerializer: aggregate([]).OfType().Where(to => (to.Name == "TestName")).SelectMany(to => to.TestDictionary)
      

      So I need to pull the whole dictionary locally and then parse it from there. It's not ideal, but there's a workaround. Am I missing something in the attributes or data structure that would allow this to work? If truly not supported, is there a plan to support $unwind via LINQ for Dictionary objects?

      Data storage object:

      public class TestObject
      {
          public string Name {get;set;};
          [BsonDictionaryOptions( DictionaryRepresentation.ArrayOfArrays )]
          public Dictionary<string,string> TestDictionary { get; set; } = new Dictionary<string, string>();
      }
      

      Aggregation query:

      var query = MongoCollection.AsQueryable()
                      .OfType<TestObject>()
                      .Where( to => to.Name == "TestName" )
                      .SelectMany( to => to.TestDictionary );
       
      string queryText = query.ToString();
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            Benson Ben
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: