本文介绍了Mongo C#驱动程序-使用嵌套动态构建过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设类似嵌套表达式
如何使用多个Builders对象并从此类表达式构建完整的过滤器?
How to use multiple Builders objects and build a complete filter out of such an expression?
推荐答案
Builders
是非常灵活的类,它还具有覆盖运算符"& = AND"和" | = OR"
Builders
is really flexible class, it also has overridden operators "& = AND" and "| = OR"
您的示例将是
var filter = Builders<User>.Filter.Eq(x => x.A, "1");
filter = filter & (Builders<User>.Filter.Eq(x => x.B, "4") | Builders<User>.Filter.Eq(x => x.B, "5"));
这篇关于Mongo C#驱动程序-使用嵌套动态构建过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!