1

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);
Amit Joshi
  • 15,448
  • 21
  • 77
  • 141

1 Answers1

1

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.

Amit Joshi
  • 15,448
  • 21
  • 77
  • 141