C# MongoDB 驱动程序 2.15.0 无法使用 Linq 执行 In Query
C# MongoDB Driver 2.15.0 unable to execute In Query with Linq
我正在尝试从 MongoDB 获取我的结果集。我需要在这里使用 In 过滤器。这是我尝试获取数据的代码。
IMongoCollection<VaersVax> vaersVaxCollection = mongoDatabase.GetCollection<VaersVax>("VaersVax");
var query = vaersVaxCollection.AsQueryable().Where(x => x.VAX_MANU.In(vaxManuList) && x.VAX_NAME.In(vaxNameList) && x.VAX_TYPE.In(vaxTypeList));
var list = query.Select(x => x.VAERS_ID).ToHashSet();
当我尝试获取结果时出现错误;
System.ArgumentException: Unsupported filter: {document}{VAX_MANU}.In(value(System.String[])).
at MongoDB.Driver.Linq.Linq2Implementation.Translators.PredicateTranslator.Translate(Expression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.PredicateTranslator.TranslateAndAlso(BinaryExpression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.PredicateTranslator.Translate(Expression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.PredicateTranslator.TranslateAndAlso(BinaryExpression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.PredicateTranslator.Translate(Expression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.PredicateTranslator.Translate(Expression node, IBsonSerializerRegistry serializerRegistry)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.QueryableTranslator.TranslateWhere(WhereExpression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.QueryableTranslator.Translate(Expression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.QueryableTranslator.TranslateSelect(SelectExpression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.QueryableTranslator.Translate(Expression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.QueryableTranslator.TranslatePipeline(PipelineExpression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.QueryableTranslator.Translate(Expression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.QueryableTranslator.Translate(Expression node, IBsonSerializerRegistry serializerRegistry, ExpressionTranslationOptions translationOptions)
at MongoDB.Driver.Linq.Linq2Implementation.MongoQueryProviderImpl`1.Translate(Expression expression)
at MongoDB.Driver.Linq.Linq2Implementation.MongoQueryProviderImpl`1.Execute(Expression expression)
at MongoDB.Driver.Linq.Linq2Implementation.MongoQueryableImpl`2.GetEnumerator()
at System.Collections.Generic.HashSet`1.UnionWith(IEnumerable`1 other)
at System.Collections.Generic.HashSet`1..ctor(IEnumerable`1 collection, IEqualityComparer`1 comparer)
at System.Linq.Enumerable.ToHashSet[TSource](IEnumerable`1 source, IEqualityComparer`1 comparer)
at System.Linq.Enumerable.ToHashSet[TSource](IEnumerable`1 source)
at MongoOperations.MongoHelper.getTop10MostFrequentSymptom1DataByVaxManuNameType(IEnumerable`1 vaxManuList, IEnumerable`1 vaxNameList, IEnumerable`1 vaxTypeList) in D:\KodUygulamalari\OkulProje\VaersWebAPI\MongoOperations\MongoHelper.cs:line 318
at MongoBusiness.MongoBusinessOperations.getTop10MostFrequentSymptom1DataByVaxManuNameType(IEnumerable`1 vaxManuList, IEnumerable`1 vaxNameList, IEnumerable`1 vaxTypeList)
我能否以某种方式在 MongoDB 驱动程序上执行 LINQ 查询,或者我是否应该检查不同的方法?
MongoDB.Driver 支持 linq。
例如:
IMongoCollection<VaersVax> vaersVaxCollection = mongoDatabase.GetCollection<VaersVax>("VaersVax");
var query = vaersVaxCollection.AsQueryable().Where(x => vaxManuList.Contains(x.VAX_MANU) && vaxNameList.Contains(x.VAX_NAME) && vaxTypeList.Contains(x.VAX_TYPE));
var list = query.Select(x => x.VAERS_ID).ToHashSet();
我正在尝试从 MongoDB 获取我的结果集。我需要在这里使用 In 过滤器。这是我尝试获取数据的代码。
IMongoCollection<VaersVax> vaersVaxCollection = mongoDatabase.GetCollection<VaersVax>("VaersVax");
var query = vaersVaxCollection.AsQueryable().Where(x => x.VAX_MANU.In(vaxManuList) && x.VAX_NAME.In(vaxNameList) && x.VAX_TYPE.In(vaxTypeList));
var list = query.Select(x => x.VAERS_ID).ToHashSet();
当我尝试获取结果时出现错误;
System.ArgumentException: Unsupported filter: {document}{VAX_MANU}.In(value(System.String[])).
at MongoDB.Driver.Linq.Linq2Implementation.Translators.PredicateTranslator.Translate(Expression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.PredicateTranslator.TranslateAndAlso(BinaryExpression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.PredicateTranslator.Translate(Expression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.PredicateTranslator.TranslateAndAlso(BinaryExpression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.PredicateTranslator.Translate(Expression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.PredicateTranslator.Translate(Expression node, IBsonSerializerRegistry serializerRegistry)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.QueryableTranslator.TranslateWhere(WhereExpression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.QueryableTranslator.Translate(Expression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.QueryableTranslator.TranslateSelect(SelectExpression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.QueryableTranslator.Translate(Expression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.QueryableTranslator.TranslatePipeline(PipelineExpression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.QueryableTranslator.Translate(Expression node)
at MongoDB.Driver.Linq.Linq2Implementation.Translators.QueryableTranslator.Translate(Expression node, IBsonSerializerRegistry serializerRegistry, ExpressionTranslationOptions translationOptions)
at MongoDB.Driver.Linq.Linq2Implementation.MongoQueryProviderImpl`1.Translate(Expression expression)
at MongoDB.Driver.Linq.Linq2Implementation.MongoQueryProviderImpl`1.Execute(Expression expression)
at MongoDB.Driver.Linq.Linq2Implementation.MongoQueryableImpl`2.GetEnumerator()
at System.Collections.Generic.HashSet`1.UnionWith(IEnumerable`1 other)
at System.Collections.Generic.HashSet`1..ctor(IEnumerable`1 collection, IEqualityComparer`1 comparer)
at System.Linq.Enumerable.ToHashSet[TSource](IEnumerable`1 source, IEqualityComparer`1 comparer)
at System.Linq.Enumerable.ToHashSet[TSource](IEnumerable`1 source)
at MongoOperations.MongoHelper.getTop10MostFrequentSymptom1DataByVaxManuNameType(IEnumerable`1 vaxManuList, IEnumerable`1 vaxNameList, IEnumerable`1 vaxTypeList) in D:\KodUygulamalari\OkulProje\VaersWebAPI\MongoOperations\MongoHelper.cs:line 318
at MongoBusiness.MongoBusinessOperations.getTop10MostFrequentSymptom1DataByVaxManuNameType(IEnumerable`1 vaxManuList, IEnumerable`1 vaxNameList, IEnumerable`1 vaxTypeList)
我能否以某种方式在 MongoDB 驱动程序上执行 LINQ 查询,或者我是否应该检查不同的方法?
MongoDB.Driver 支持 linq。 例如:
IMongoCollection<VaersVax> vaersVaxCollection = mongoDatabase.GetCollection<VaersVax>("VaersVax");
var query = vaersVaxCollection.AsQueryable().Where(x => vaxManuList.Contains(x.VAX_MANU) && vaxNameList.Contains(x.VAX_NAME) && vaxTypeList.Contains(x.VAX_TYPE));
var list = query.Select(x => x.VAERS_ID).ToHashSet();