请参阅这个答案 https://stackoverflow.com/a/49778821/5779732(也有问题链接)了解如何实施IN
clause.
要转动IN
如上所述的条款NOT IN
子句,使用最后一个bool not
范围。
这是可选参数,默认值为false
.
因此;尽管如此明显,但还是有点hidden因此未被发现的.
文档也没有明确提及。
以下是 Dapper Extensions 源代码中定义的每个谓词的定义:
public static class Predicates
{
public static IBetweenPredicate Between<T>(Expression<Func<T, object>> expression, BetweenValues values, bool not = false) where T : class;
public static IExistsPredicate Exists<TSub>(IPredicate predicate, bool not = false) where TSub : class;
public static IFieldPredicate Field<T>(Expression<Func<T, object>> expression, Operator op, object value, bool not = false) where T : class;
public static IPropertyPredicate Property<T, T2>(Expression<Func<T, object>> expression, Operator op, Expression<Func<T2, object>> expression2, bool not = false)
where T : class
where T2 : class;
}
示例代码如下:
var predicate = Predicates.Field<Customer>
(f => f.CustomerID, Operator.Eq, listOfIDs, true);
观察数值true
对于上面代码中的最后一个参数。这listOfIDs
is an IEnumerable
您的数据类型。
请参阅this https://github.com/tmsmith/Dapper-Extensions/wiki/Predicates#multiple-compound-predicates-predicate-group获取更多源代码。