在短小精悍的动态where子句 [英] Dynamic where clause in dapper

查看:130
本文介绍了在短小精悍的动态where子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能与短小精悍飞添加和删除标准是什么?我需要这个实现用户驱动的过滤。这是不可行的有,因为有太多的组合,每个过滤器的查询。

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.

推荐答案

在最基本的层面上,你只需建立TSQL动态的一个StringBuilder - 增加额外的和c.Name = @name 等。不要担心额外参数;送他们都 - 库检查该命令并不会添加显然不使用任何参数。还有第二个,对于这种特定情况下新的API,但我不记得具体而不检查(和我不是在一台电脑)。我可以尝试在以后添加更多的细节(假设SAM不会)。

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

这篇关于在短小精悍的动态where子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆