简体   繁体   English

在多个表上使用SubSonic Query

[英]Using SubSonic Query to on multiple tables

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. 对于一个表,我可以使用Query对象,但是我不知道如何添加多个表进行查询。

You neet to join them, much like you would do in SQL. 您很想加入他们,就像在SQL中一样。 If you have a foreign key relationship in the schema, Subsonic is smart enough to figure the joins directly: 如果您在架构中具有外键关系,那么Subsonic足够聪明,可以直接计算联接:

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: 如果表之间没有FKI,则需要手动指定每个表中的列以创建联接:

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. 请记住,您只能在简单的FKI约束下加入它们。 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. 例如,我发现没有简单的方法可以直接从SubSonic执行“在Table1.FKI上进行Table2.FKI = Table2.ID和Table2.CreateDate> Table1.CreateDate的内部联接”。

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. 使用SubSonic多表联接的一个大缺点是,如果两个表中的列名相同,则会遇到麻烦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM