Search code examples
c#linqlinq-to-dataset

have join multiple table and get the output in DataRow in LINQ


HI,

I have a scenario where i have join multiple table and get the output in DataRow(All the Rows return by the query).

SQL Query:

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

I know how to perform join in LINQ but how can i select all the column(Rows) in select statement of LINQ.


Solution

  • 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
                   };
    

    The anonymous type contains all data you want, you can easily visit one column by:

    result.FirstOrDefault().Zone.SomeField