Join 亚音速问题中的左连接
我是亚音速的初学者,我使用的是2.1版。我想在此查询中执行左联接。查询如下所示:Join 亚音速问题中的左连接,join,subsonic,Join,Subsonic,我是亚音速的初学者,我使用的是2.1版。我想在此查询中执行左联接。查询如下所示: select ... from tableA left join tableB on tableA.Cola=tableB.Colb and tableB.Colc='some value' 我想知道如何执行和tableB.Colc='some value'条件。我试过这样的方法: new SubSonic.Select().From("tableA").LeftOuterJoin ("tableB","Col
select ...
from tableA
left join tableB on tableA.Cola=tableB.Colb and tableB.Colc='some value'
我想知道如何执行和tableB.Colc='some value'
条件。我试过这样的方法:
new SubSonic.Select().From("tableA").LeftOuterJoin
("tableB","Colb","tableA","Cola").AndExpression("Colc").IsEqualTo("some value")
但是生成的语句不是我想要的。这可能不是您想要的,但是在亚音速中执行类似操作的最佳方法是使用视图,因此创建select作为视图,然后在代码中使用view对象。在3+中,linq使您更容易完成您正在尝试的内容,在我看来,查询的部分应该是where条件(您正在尝试根据tableB.Colc的值等于“某个值”来过滤结果)。因此,我认为您的sql查询应该是这样的:
select ...
from tableA left join tableB on tableA.Cola=tableB.Colb
where tableB.Colc='some value' or tableB.Colc is null
如果是这种情况,那么在亚音速下,您可以:
new SubSonic.Select()
.From("tableA").LeftOuterJoin ("tableB","Colb","tableA","Cola")
.Where("Colc").IsEqualTo("some value")
.Or("Colc").IsNull()