Dynamic where clause in dapper

后端 未结 1 1966
南方客
南方客 2021-02-20 18:39

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

1条回答
  •  终归单人心
    2021-02-20 18:56

    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).

    0 讨论(0)
提交回复
热议问题