Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic where clause in dapper

Tags:

c#

orm

dapper

Is it possible to add and remove criteria on the fly with dapper? I need this to implement user driven filtering. It is not feasible to have a query for each filter as there are too many combinations.

like image 215
NabilS Avatar asked Oct 15 '11 12:10

NabilS


1 Answers

At the most basic level, you can just build the TSQL dynamically in a StringBuilder - adding extra and c.Name = @name etc . Don't worry about extra parameters; send them all - the library inspects the command and doesn't add any parameters that obviously aren't used. There is a second, newer API for this specific scenario, but I can't remember the specifics without checking (and I'm not at a computer). I can try to add more details later (assuming Sam doesn't).

like image 71
Marc Gravell Avatar answered Nov 12 '22 06:11

Marc Gravell