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.
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
This is untested but something close to this should work. Assuming your data context is call Context. This is a translation of what you have above.
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;
If you want to select all of the data then you need to do something like this.
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
};
精彩评论