[CSHARP-732] ICollection<T>.Contains is not supported in a LINQ Expression Created: 19/Apr/13  Updated: 20/Mar/14  Resolved: 19/Apr/13

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.8.1
Fix Version/s: 1.8.2

Type: Bug Priority: Minor - P4
Reporter: Zaid Masud Assignee: Craig Wilson
Resolution: Done Votes: 0
Labels: LINQ
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by CSHARP-785 Custom/unsupported collections with t... Closed

 Description   

This unit test works when you declare the type as int[], but not when you declare the type as IList<int>.

I believe this also affects LINQ expressions using Contains or In. IEnumerable, array types, and List types are supported but IList throws an Unsupported exception.

[Test]
public void TestInExpressionWithIList()
{
    IList<int> list = new[] { 2, 4, 6 };
    var query = Query<A>.Where(a => list.Contains(a.X));
    var expected = "{ \"x\" : { \"$in\" : [2, 4, 6] } }";
    Assert.AreEqual(expected, query.ToJson());
}



 Comments   
Comment by Craig Wilson [ 19/Apr/13 ]

Yep, I've already fixed it and pushed it up for code review. In the meantime, just do a .ToList() on whatever you are using.

Thanks for reporting.

Comment by Zaid Masud [ 19/Apr/13 ]

The same problem exists for ICollection as well.

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