使用 SubSonic 查询对多个表进行查询

发布于 2024-07-20 07:29:05 字数 58 浏览 3 评论 0原文

我想使用亚音速从多个表中选择行。 对于一张表,我可以使用查询对象,但我不知道如何添加多个表进行查询。

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 技术交流群。

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

发布评论

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

评论(1

云柯 2024-07-27 07:29:05

您需要加入它们,就像在 SQL 中一样。
如果模式中有外键关系,Subsonic 足够智能,可以直接计算连接:

DataSet DS = DB.Select().From<Table1>().InnerJoin<Table2>().ExecuteDataSet();

如果表之间没有 FKI,则需要手动指定每个表中的列来创建连接:

DataSet DS = DB.Select().From<Table1>().InnerJoin(Table1.FKIColumn,Table2.IDColumn).ExecuteDataSet();

同样,您可以创建左/右外连接等。

请记住,您只能在简单的 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:

DataSet DS = DB.Select().From<Table1>().InnerJoin<Table2>().ExecuteDataSet();

If you don't have a FKI between the tables, you need to manually specify the columns from each table to create the join:

DataSet DS = DB.Select().From<Table1>().InnerJoin(Table1.FKIColumn,Table2.IDColumn).ExecuteDataSet();

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.

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