[CSHARP-1542] Using abstract type within Queryable Linq statement Created: 21/Jan/16  Updated: 18/May/16  Resolved: 17/Mar/16

Status: Closed
Project: C# Driver
Component/s: Linq
Affects Version/s: 2.2.2
Fix Version/s: 2.2.4

Type: Bug Priority: Major - P3
Reporter: Stephen Bond Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: Bug
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CSHARP-1509 FilterDefinitionBuilder Where can res... Closed
is related to CSHARP-1604 Type casting in UpdateDefinition Linq... Closed
Backwards Compatibility: Fully Compatible

 Description   

When querying against a property that is defined as an abstract base type the driver fails to handle a cast to a concrete type within the where clause.

The following example worked within the 1.92 of the C# driver.

Below is an example:

public class Entity
{
 public A Result { get; set; }
}
 
[BsonKnownTypes(new Type[] { typeof(B), typeof(C)})]
public abstract class A
{
 public string Id { get; set; }
}
 
public class B : A
{
 public string PropertyOnB { get; set; }
}
 
public class C : A
{
 public string PropertyOnC { get; set; }
}

Query:

collection.AsQueryable().Where(q => ((B)q.Result).PropertyOnB == "TestResult").ToList();
 
Executing this query gives the following exception:
 
Convert({document}{Results}).PropertyOnB is not supported



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

Author:

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

Message: CSHARP-1542: support TypeAs expressions.
Branch: v2.2.x
https://github.com/mongodb/mongo-csharp-driver/commit/a29fb1316237579b6d9a7570a7e82dfc62d7df68

Comment by Githook User [ 17/Mar/16 ]

Author:

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

Message: CSHARP-1542: support TypeAs expressions.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/de410dcf378433383e5198265f993fe0328e7a8a

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