0

你好,

我有一个场景,我连接了多个表并在 DataRow 中获取输出(查询返回的所有行)。

SQL查询:

SELECT  Fr.InterCodeId   
        FROM    
        CodeShareInterline Fr,    
        Airline A,Zone Z   #
        WHERE    
        A.AirlineId = Fr.AirlineId   
        And Fr.ContractId=Z.ContractId

我知道如何在 LINQ 中执行连接,但是如何在 LINQ 的 select 语句中选择所有列(行)。

4

2 回答 2

0

这是未经测试的,但接近这个的东西应该可以工作。假设您的数据上下文是调用上下文。这是你上面的翻译。

var o = from fr in Context.CodeShareInterline
            join a from Context.Airline on a.AirlineId == fr.AirlineId 
            join z from Context.Zone on fr.ContactId == z.ContactId
            select fr.InterCodeId;

如果要选择所有数据,则需要执行以下操作。

var o = from fr in Context.CodeShareInterline
            join a from Context.Airline on a.AirlineId == fr.AirlineId 
            join z from Context.Zone on fr.ContactId == z.ContactId
            select new { 
                        Interline = fr,
                        AirLine = a,
                        Zone = z
                       };
于 2011-03-23T09:33:43.963 回答
0
var result = from fr in dataContext.CodeShareInterline
            from a in dataContext.AirLine
            from z in dataContext.Zone
            where a.AirlineId == fr.AirlineId && fr.ContractId == z.ContractId
            select new 
               {
                   Interline = fr,
                   AirLine = a,
                   Zone = z
               };

匿名类型包含您想要的所有数据,您可以通过以下方式轻松访问一列:

result.FirstOrDefault().Zone.SomeField
于 2011-03-23T09:35:48.223 回答