C# 带有元组的MongoDB查询

C# 带有元组的MongoDB查询,c#,mongodb,mongodb-.net-driver,C#,Mongodb,Mongodb .net Driver,我的文件结构如下: { Foo: BinData Bar: Integer } 我想通过Foo和Bar两个字段搜索这些文档(它们有其他字段)(它们一起组成了一个要搜索的键) 我目前正在这样做: List<Tuple<byte[], int>> fooBarList = mySearchValues; return Collection.AsQueryable().OfType<MyType>() .Where(x =&

我的文件结构如下:

{
  Foo: BinData
  Bar: Integer
}
我想通过Foo和Bar两个字段搜索这些文档(它们有其他字段)(它们一起组成了一个要搜索的键)

我目前正在这样做:

List<Tuple<byte[], int>> fooBarList = mySearchValues;
return Collection.AsQueryable().OfType<MyType>()
                .Where(x => fooBarList.Any(y => x.Foo == y.Item1 && x.Bar == y.Item2))
                .ToArray();

有人已经有类似的问题了吗?如果有,我怎么做?我不能使用$in,因为它只对单个文档字段进行操作。

当前版本的驱动程序(1.x)是为.NET 3.5构建的,并且不知道如何序列化元组。如果愿意,您可以编写一个元组序列化程序并注册它,以使此查询能够工作


然而,我认为不使用元组而创建一个简单的私有类并使用它会更容易。

嗨,Craig,谢谢你的帮助。使用私有类或匿名类无法解决此问题。它只是给出了相同的错误,但类名不同。无法确定表达式的序列化信息:Temp[]:{Namespace+Temp}。能否告诉我mongodb查询应该是什么样的?查询应该查找Foo和Bar都与查询数据列表(Foo和Bar对)匹配的文档。这里有一个C#示例,我希望这应该是上面的样子。是的,我看到了C#示例,但我不确定(仔细查看后)您在MongoDB中输入的查询是否可能。你能用mongodb查询语言提供你想要的查询吗?我会帮你把它转换成C?
System.NotSupportedException: Unable to determine the serialization information for the expression: System.Collections.Generic.List`1[System.Tuple`2[System.Byte[],System.Int32]].
   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(MethodCallExpression methodCallExpression)
   at MongoDB.Driver.Linq.PredicateTranslator.BuildQuery(Expression expression)
   at MongoDB.Driver.Linq.PredicateTranslator.BuildQuery(Expression expression)
   at MongoDB.Driver.Linq.SelectQuery.Execute()
   at MongoDB.Driver.Linq.MongoQueryable`1.GetEnumerator()
   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)