I found how to implement IN
clause using Dapper Extensions here.
Now, I want to implement NOT IN
clause.
So, I am expecting SQL query something like below:
SELECT * FROM MyTable
WHERE MyField NOT IN (param1, param2)
But I could not find anything about NOT IN
or NOT
clause in Dapper Extensions.
How can I implement NOT IN
clause with Dapper Extensions Predicate?
Please refer to this answer (linked in question as well) to understand how to implement
IN
clause.To turn the
IN
clause as mentioned above toNOT IN
clause, use the lastbool not
parameter.This is optional parameter and default value for it is
false
.That is why; even though so obvious, it is bit hidden and hence undiscovered.
Documentation does not mention it explicitly either.
Below are the definitions of each predicate defined in Dapper Extensions source code:
Sample code is as below:
Observe the value
true
for last parameter in above code. ThelistOfIDs
is anIEnumerable
of your data type.Please refer to this for more source code.