dapper 中的动态 where 子句

发布于 2024-12-09 18:01:44 字数 69 浏览 1 评论 0原文

是否可以使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小梨窩很甜 2024-12-16 18:01:44

在最基本的层面上,您可以在 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文