如何通过 subsonic 对象从连接表返回数据?
我在 Subsonic 3 上使用 ActiveRecord,实际上我想这样做:
select * from foo
left outer join bar on bar.Id = foo.barId
where foo.someProperty = 2
我编写了一个存储过程来获取数据,但 Subsonic 仅创建了对象来保存 foo 和 bar 中的列。
将数据返回到单个对象中以便我可以绑定它的最佳方法是什么。理想情况下,我希望它位于列表中<>但如果不写自己的类,似乎没有亚音速提供的方法。
I'm using ActiveRecord on Subsonic 3 and I effectively want to do this:
select * from foo
left outer join bar on bar.Id = foo.barId
where foo.someProperty = 2
I've written a stored procedure to fetch the data but Subsonic has only created objects to hold the columns from foo and bar.
What's the best way of returning the data into a single object so I can just bind it. Ideally I want it to be in a list<> but without writing my own class, there doesn't seem to be a way provided by subsonic.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里有几个选项...
您可以创建一个执行连接的数据库视图,并让 SubSonic 为您的视图生成数据类型,然后您的选择就像从任何其他表中进行选择一样。
或者,您可以使用 Linq 表达式来连接到匿名或动态类型(如果您使用的是 .net 4)例如:
当然,另一种选择是执行上面的 Linq 表达式,但定义您自己的类来保存返回数据,并选择进去。
You have a couple options here...
You could create a database view that does your join, and have SubSonic generate a data type for your view, then your select would be just like selecting from any other table.
Alternatively, you could use a Linq expression to do the join into an anonymous or dynamic type (if you are using .net 4) For example:
Of course another alternative is to do the Linq expression above, but define your own class to hold the returned data, and select into it.