0

精确地使用内部联接进行选择,该内部联接在表中的多个字段中具有关系

示例:

 DataSet dt = new Select().From(SubConta.Schema)
         .InnerJoin(PlanoContabilSubConta.EmpSubContaColumn, SubConta.CodEmpColumn)
         .InnerJoin(PlanoContabilSubConta.FilSubContaColumn, SubConta.CodFilColumn)
         .InnerJoin(PlanoContabilSubConta.SubContaColumn, SubConta.TradutorColumn)
         .Where(PlanoContabilSubConta.Columns.EmpContabil).IsEqualTo(cEmp)
         .And(PlanoContabilSubConta.Columns.FilContabil).IsEqualTo(cFil)
         .And(PlanoContabilSubConta.Columns.Conta).IsEqualTo(cTrad)
         .ExecuteDataSet();

但是生成的sql是错误的:

exec sp_executesql N'/* GetDataSet() */ SELECT [dbo].[SubContas].[CodEmp], [dbo].[SubContas].[CodFil], [dbo].[SubContas].[Tradutor], [dbo].[SubContas].[Descricao], [dbo].[SubContas].[Inativa], [dbo].[SubContas].[DataImplantacao]

 FROM [dbo].[SubContas]
 INNER JOIN [dbo].[PlanoContabilSubContas] ON [dbo].[SubContas].[CodEmp] = [dbo].[PlanoContabilSubContas].[EmpSubConta]
 INNER JOIN [dbo].[PlanoContabilSubContas] ON [dbo].[SubContas].[CodFil] = [dbo].[PlanoContabilSubContas].[FilSubConta]
 INNER JOIN [dbo].[PlanoContabilSubContas] ON [dbo].[SubContas].[Tradutor] = [dbo].[PlanoContabilSubContas].[SubConta]
 WHERE EmpContabil = @EmpContabil0
 AND FilContabil = @FilContabil1
 AND Conta = @Conta2
',N'@EmpContabil0 varchar(1),@FilContabil1 varchar(1),@Conta2 varchar(1)',@EmpContabil0='1',@FilContabil1='1',@Conta2='1'

应该做什么来生成这个sql?

exec sp_executesql N'/* GetDataSet() */ SELECT [dbo].[SubContas].[CodEmp], [dbo].[SubContas].[CodFil], [dbo].[SubContas].[Tradutor], [dbo].[SubContas].[Descricao], [dbo].[SubContas].[Inativa], [dbo].[SubContas].[DataImplantacao]

     FROM [dbo].[SubContas]
     INNER JOIN [dbo].[PlanoContabilSubContas] ON [dbo].[SubContas].[CodEmp] = [dbo].[PlanoContabilSubContas].[EmpSubConta] AND
     [dbo].[SubContas].[CodFil] = [dbo].[PlanoContabilSubContas].[FilSubConta] AND
     [dbo].[SubContas].[Tradutor] = [dbo].[PlanoContabilSubContas].[SubConta]
     WHERE EmpContabil = @EmpContabil0
     AND FilContabil = @FilContabil1
     AND Conta = @Conta2
    ',N'@EmpContabil0 varchar(1),@FilContabil1 varchar(1),@Conta2 varchar(1)',@EmpContabil0='1',@FilContabil1='1',@Conta2='1'
4

1 回答 1

0

看起来你不能在 SubSonic 2 中加入多个列,你可以创建一个 SQL 视图,按照你的意愿加入,然后让 SubSonic 为该视图生成一个模型。

于 2009-08-26T13:41:05.703 回答