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

OfType doesn't work for an embedded array.

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.2.4
    • Affects Version/s: 2.2.3
    • Component/s: API
    • Environment:
      c# / net 4.5, mongo 3.2.3

      please find method which calls to get people entries with casting to derived class object

      var people = database.GetDatabase("Test") .GetCollection<Person>("People").AsQueryable();
      var x = people.Where(z => z.Addresses.OfType<Email>().Any(e => e.MailTo == "not@home.com"));
      throws an exception:
      "The method OfType is not supported in the expression tree:

      {document} {Addresses}

      .OfType()."

      class Person
      {
      public List<Address> Addresses

      { get; set; }
      }
      class Address
      {
      }
      class Phone : Address
      {
      public string Number { get; set; }

      }
      class Email : Address
      {
      public string MailTo

      { get; set; }

      }

            Assignee:
            craig.wilson@mongodb.com Craig Wilson
            Reporter:
            profesor79 Greg
            Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: