How to write 'Not Equal' clause in Dapper Extension?

533 Views Asked by At

I want to create below SQL query in dapper extentions.

SELECT DISTINCT Description FROM tblPeople WHERE ID = 2 AND
 (AddressTown IS NOT NULL AND AddressTown<>'') ORDER BY Description ;

I have tried so far:

PredicateGroup pgMain = new PredicateGroup 
  { Operator = GroupOperator.And, Predicates = new List<IPredicate>() };
pgMain.Predicates.Add(Predicates.Field<tblPeople >(f => f.ID, Operator.Eq, 2));  
var peopleList = connection.GetList<tblPeople>(pgMain);
1

There are 1 best solutions below

0
Amit Joshi On

You can use the last bool not parameter. This is optional parameter and default value for it is false.

So, your new code should be like as below:

pgMain.Predicates.Add(Predicates.Field<tblPeople>(f => f.ID, Operator.Eq, 2, true));

Observe the value true for last parameter in above code.

Please refer to this answer for more details.