IQueryable for Subsonic 存储过程
我需要使用存储过程从数据库获取数据,但我还想使用 IQueryable 对结果添加一些过滤。我正在使用 subsonic,但目前看不到使用 subsonic sp 和 IQueryable 的方法。我唯一的想法是创建一个将执行所有所需连接的视图。然后执行调用以查看类似 subsonic 的表:
MyView.All()
Subsonic All 返回 IQueryable,我可以在代码中添加过滤子句,而不是在 sp 中添加 where 。不确定这是否是可行的解决方案?
I need to use stored procedure to get data from DB, but I would also like to use IQueryable to add some filtering to results. I'm using subsonic and for now can't see a way to use subsonic sp and IQueryable. The only idea I have is to make a view that will perform all required joins. Then perform call to view like to table with subsonic:
MyView.All()
Subsonic All returns IQueryable and instead of adding where in sp I can add filter clauses in code. Not sure if this is viable solution or not?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,我已经完成了要添加的这个解决方案查看我的 SubSonic 对象和 IQueryable 以添加过滤。
Ok, I`ve finished with this solution to add views to my SubSonic objects and IQueryable to add filtering.
IQueryable
允许将 LINQ 查询转换为 SQL 语句。将 IQueryable 与存储过程结合使用与将 SQL 语句与存储过程混合使用相同,例如 SELECT * FROM dbo.MyStoredProc WHERE x > 100 。由于这行不通,因此将IQueryable
与存储过程混合是没有用的,因为无法在 SP 结果返回之前对其进行过滤。您正在寻找的是客户端(.NET 端)过滤。为此,您可以简单地使用
IEnumerable
。当存储过程返回项目集合时,您仍然可以对该集合使用 LINQ 查询。IQueryable
allows translating LINQ queries into SQL statements. UsingIQueryable
in conjunction with stored procedures is the same as mixing a SQL statement with a stored procedure, such asSELECT * FROM dbo.MyStoredProc WHERE x > 100
. Since this won't work, mixingIQueryable
with a stored procedure is useless, because there is no way to filter the results of the SP before they return.What you are looking for is client-side (.NET side) filtering. For this you can simply use
IEnumerable
. When your stored procedure returns a collection of items, you can still use LINQ queries over that collection.