[CSHARP-1589] OfType doesn't work for an embedded array. Created: 02/Mar/16  Updated: 18/May/16  Resolved: 14/Mar/16

Status: Closed
Project: C# Driver
Component/s: API
Affects Version/s: 2.2.3
Fix Version/s: 2.2.4

Type: Bug Priority: Minor - P4
Reporter: Greg Assignee: Craig Wilson
Resolution: Done Votes: 2
Labels: driver
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

c# / net 4.5, mongo 3.2.3



 Description   

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; }

}



 Comments   
Comment by Githook User [ 14/Mar/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1589: allow OfType to be used on embedded arrays.
Branch: v2.2.x
https://github.com/mongodb/mongo-csharp-driver/commit/063356d1f85f781ed3c15b565d6ec9a306148baf

Comment by Githook User [ 14/Mar/16 ]

Author:

{u'username': u'craiggwilson', u'name': u'Craig Wilson', u'email': u'craiggwilson@gmail.com'}

Message: CSHARP-1589: allow OfType to be used on embedded arrays.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/10b034e1d5a814d963c05d8942b657589c0d4d75

Comment by Greg [ 02/Mar/16 ]

stack overflow source: http://stackoverflow.com/questions/35758112/find-a-mongodb-document-based-on-element-match-of-a-specific-subtype-type

Generated at Wed Feb 07 21:40:04 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.