类型数据集中的 where 子句的动态参数可能吗?
普通的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,您可能想回顾一下 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