[CSHARP-1980] Support Where(c => c.GetType() == type) in LINQ Created: 08/May/17  Updated: 31/Mar/22

Status: Backlog
Project: C# Driver
Component/s: API, Linq
Affects Version/s: 2.4.3
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Lewis Gill Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 10 x64



 Description   

I think this is the same issue as CSHARP-1714.

However, I cannot use the "is" clause workaround because I have a set of Type variables that I'm using to build up a dynamic LINQ query, so I can't use the "is" clause, which requires a constant expression.

Is there now a way to make the following work with MongoDB?

Type type1 = typeof(MyObject1);
Type type2 = typeof(MyObject2);
query.Where( c => c.GetType() == type1 || c => c.GetType() == type2);

I've manually verified that using an "is" clause does work on the same query.



 Comments   
Comment by Brecht Vanhaesebrouck [ 26/Mar/19 ]

I'd love to see this feature too.

Comment by Robert Stam [ 16/May/17 ]

I've reclassified this as an improvement request rather than a bug.

This particular LINQ query is currently not supported.

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