C#学习教程:MongoDBc#驱动程序:不区分大小写使用linq在列表中使用或包含比较集合上的子句,将属性的低级版本与内存中我的列表的小写版本进行比较。像这样;items=items.Where(i=>listToCheck.Contains(i.Property.ToLower()));我也试过...items=items.Where(i=>i.Property.ToLower().In(listToCheck));我认为这实际上是正确的并且应该有效,但可能尚未实施。我收到一条错误消息,提示“与ToLower()命令相关的‘不受支持的where子句’。据我所知,驱动程序目前无法执行此操作,因为它必须对“IN”查询使用正则表达式,而我看不到.我想知道是否可能,如果可能的话,怎么做?我终于找到了这个问题的解决方案,经过大量挖掘我发现toLower()方法没有在mongoDblinq提供程序中实现,所以我不得不使用MongoQuery而不是我为字符串和列表创建了一些扩展方法,它采取一个字符串或列表作为源并将其转换为bson正则表达式internalstaticListConvertToCaseInsensitiveRegexList(thisIEnumerablesource){returnsource.Select(range=>newBsonRegularExpression("/^"+range.Replace("+",@"+")+"$/i")).Cast().ToList();}internalstaticListConvertToEndsWithRegexList(thisIEnumerablesource){returnsource.Select(range=>newBsonRegularExpression("/"+range.Replace("+",@"+")+"$/i")).Cast().ToList();}internalstaticBsonRegularExpressionToCaseInsensitiveRegex(thisstringsource){returnnewBsonRegularExpression("/^"+source.Replace("+",@"+")+"$/i");}并像这样使用它们...以上是C#学习教程:MongoDBc#driver:CaseInsensitiveusinglinqinalistorcontains比较所有分享的内容,如果对你有用还需要进一步了解C#学习教程,希望大家多多关注—varcolors=newList{"Red","blue","white"};varquery=查询.In(v=>v.Colour,colours.ConvertToCaseInsensitiveRegexList());this.Find(query).ToList();本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
