使用 SubSonic 查询对多个表进行查询
我想使用亚音速从多个表中选择行。 对于一张表,我可以使用查询对象,但我不知道如何添加多个表进行查询。
I want to select rows from multiple tables using subsonic. For one table I can use Query object, but I don't know how I can add more than one tables to query.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要加入它们,就像在 SQL 中一样。
如果模式中有外键关系,Subsonic 足够智能,可以直接计算连接:
如果表之间没有 FKI,则需要手动指定每个表中的列来创建连接:
同样,您可以创建左/右外连接等。
请记住,您只能在简单的 FKI 约束下加入它们。 例如,我发现没有简单的方法可以直接从 SubSonic 执行“INNER JOIN Table2 on Table1.FKI = Table2.ID and Table2.CreateDate>Table1.CreateDate”。
使用 SubSonic 多表连接的一个很大的缺点是,如果两个表中具有相同名称的列,您将会遇到麻烦。
You neet to join them, much like you would do in SQL.
If you have a foreign key relationship in the schema, Subsonic is smart enough to figure the joins directly:
If you don't have a FKI between the tables, you need to manually specify the columns from each table to create the join:
Similarly you can create the Left/Right Outer joins,etc.
Remeber you can only join them on simple FKI constraints. For example I found no easy way to do "INNER JOIN Table2 on Table1.FKI = Table2.ID and Table2.CreateDate>Table1.CreateDate" directly from SubSonic.
And a big downside to using SubSonic multiple table joins is that you will run into troubles if you have identically named columns in both tables.