dapper 中的动态 where 子句
是否可以使用 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在最基本的层面上,您可以在 StringBuilder 中动态构建 TSQL - 添加额外的
和 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).