类型数据集中的 where 子句的动态参数可能吗?

发布于 2024-08-21 23:00:22 字数 315 浏览 3 评论 0原文

普通的 ASP.NET TableAdapter 适用于简单的 where 子句,例如 - “where city = @city and state = @state and zip = @zip”

但是我如何设计一个允许我使用参数的任意组合的 DAL - “仅按城市搜索”或“按邮政编码和州搜索”或“按城市和州搜索”......或者更复杂的“按邮政编码搜索,但如果@zip为空,则按城市搜索”... .

如何设计支持这种动态 where 条件的 DAL?带有表适配器的类型化数据集是最好的方法吗?目前,我只是对普通数据集使用动态 SQL 查询,并尝试将其转换为某种强类型 DAL。

The normal ASP.NET TableAdapters are good for simple where clauses, for example - "where city = @city and state = @state and zip = @zip"

But how do I design a DAL that allows me to use any combination of the parameters - "search only by city" or "search by zip and state" or "search by city and state".....or even more complex "search by zip but if @zip is null then search by city"....

How can I design a DAL that supports such dynamic where conditions? Are typed datasets with table adapters the best approach? Currently, I'm just using dynamic SQL queries with normal datasets and I'm trying to convert it into some sort of strongly typed DAL.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

淡看悲欢离合 2024-08-28 23:00:22

在我看来,您可能想回顾一下 Dynamic LINQ。当存在这种动态条件时,它会很有帮助。我发现此处的代码示例非常有帮助。

哈特哈,
席德

It sounds to me like you might want to review Dynamic LINQ. It can be helpful when such dynamic conditions exist. I have found the Code Samples here to be very helpful.

HTH,
Sid

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