-
Type: Bug
-
Resolution: Cannot Reproduce
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
When a .NET collection type, such as ISet, defines its own Contains method, the C# compiler will (rightly) choose this implementation over the Enumerable.Contains extension method. When the collection type is unsupported by MongoDB natively, however, Mongo's client driver for C# will throw an exception because it doesn't know how to translate the Contains method invocation into a query.
The workaround at the moment is not too bad – calling Enumerable.Contains(collection, item to check) rather than collection.Contains(item to check) translates properly by the driver. However, this is a bit hackish and is definitely not easy to read.
I think this is a situation where "if it looks like a duck and quacks like a duck, its a duck" applies. If a type implements IEnumerable<T>, defines a method called Contains, and that method takes one argument of type T, you should translate it just like you would do with the extension method or one of the supported collection types' Contains method.
- duplicates
-
CSHARP-732 ICollection<T>.Contains is not supported in a LINQ Expression
- Closed