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

Support creation of polymorphic arrays in LINQ

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: 3.2.1
    • Component/s: Linq
    • None
    • None
    • Dotnet Drivers
    • None
    • None
    • None
    • None
    • None
    • None

      The LINQ translator checks that all items in an array are serialized the same way by verifying that they are all serialized using the same serializer. But this approach doesn't account for polymorphism.

      Given the following classes:

      public sealed class C
      {
          public int Id { get; set; }
          public Cat Cat { get; set; }
          public Dog Dog { get; set; }
      }
       
      public abstract class Animal
      {
      }
       
      public sealed class Cat : Animal
      {                               
      }                               
                                      
      public sealed class Dog : Animal
      {                               
      }                               
      

      The following query should work (but currently an exception is thrown):

      var queryable = collection.AsQueryable()
          .Select(x => new Animal[] { x.Cat, x.Dog });
      

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            robert@mongodb.com Robert Stam
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              None
              None
              None
              None