-
Type:
Bug
-
Resolution: Won't Fix
-
Priority:
Major - P3
-
None
-
Affects Version/s: 1.8.3
-
Component/s: None
-
None
-
None
-
Fully Compatible
-
None
-
None
-
None
-
None
-
None
-
None
Take these queries and try to run them. You will get the following exception:
ObjectId?[] supplierIds =
(from s in mongo.Suppliers
where s.Country == supplierCountry
select new Nullable<ObjectId>(s.Id)).ToArray();
var supplierProducts =
(from p in mongo.Products
where supplierIds.Any(id => id == p.SupplierID)
orderby p.ProductName
select p);
Unhandled Exception: System.NotSupportedException: Unable to determine the serialization information for the expression: Nullable<ObjectId>[]:
{ 000000000000000000000016, 000000000000000000000019, 000000000000000000000002, 000000000000000000000003 }.
at MongoDB.Driver.Linq.Utils.BsonSerializationInfoFinder.GetSerializationInfo
(Expression node, Dictionary`2 serializationInfoCache)
at MongoDB.Driver.Linq.PredicateTranslator.BuildAnyQuery(MethodCallExpression
methodCallExpression)
at MongoDB.Driver.Linq.PredicateTranslator.BuildMethodCallQuery(MethodCallExp
ression methodCallExpression)
at MongoDB.Driver.Linq.PredicateTranslator.BuildQuery(Expression expression)
at MongoDB.Driver.Linq.SelectQuery.BuildQuery()
at MongoDB.Driver.Linq.SelectQuery.Execute()
at MongoDB.Driver.Linq.MongoQueryProvider.Execute(Expression expression)
at MongoDB.Driver.Linq.MongoQueryable`1.GetEnumerator()
An alternate attempt at that query with ObjectId[] rather than ObjectId[] gives basically the same failure:
ObjectId[] supplierIds =
(from s in mongo.Suppliers
where s.Country == supplierCountry
select s.Id).ToArray();
var supplierProducts =
(from p in mongo.Products
where supplierIds.Any(id => id == p.SupplierID)
orderby p.ProductName
select p);
However, if I use Contains rather than Any, it works! But it is more painful because I need to convert to an nullable ObjectId array when the source is not actually nullable (required so supplierIds.Contains() compiles):
ObjectId?[] supplierIds =
(from s in mongo.Suppliers
where s.Country == supplierCountry
select new Nullable<ObjectId>(s.Id)).ToArray();
var supplierProducts =
(from p in mongo.Products
where supplierIds.Contains(p.SupplierID)
orderby p.ProductName
select p);
I've attached the two related classes involved in the query.