如何使用linq编写内部联接查询

时间:2011-09-15 07:23:52

标签: linq-to-sql inner-join

我已经编写了一个内连接查询。在SQL Server中它工作正常,但我想使用Linq-to-SQL编写此查询。请有人帮帮我吗?

这是我在SQL Server中的查询:

select db.Firstname, db.lastname, lo.BiPayAmt, lo.Loan_ID, sc.Pmt_Id,
    sc.Terms, sc.pmt_dates, sc.LoanId
from dbo.Clients db
inner join dbo.Loans lo on db.Client_ID = lo.Client_ID
inner join dbo.SchedulePayments sc on lo.Loan_ID = sc.LoanId

1 个答案:

答案 0 :(得分:1)

粗略地说:

from db in dbo.Clients
join lo in dbo.Loans on db.Client_ID equals lo.Client_ID
join sc in dbo.SchedulePayments on lo.Loan_ID equals sc.LoanId
select new
{
    db.Firstname,
    db.lastname,
    lo.BiPayAmt,
    lo.Loan_ID,
    sc.Pmt_Id,
    sc.Terms,
    sc.pmt_dates,
    sc.LoanId
}