How to join 3 tables with lambda expression?

后端 未结 4 1984
借酒劲吻你
借酒劲吻你 2021-01-31 11:47

I have a simple LINQ lambda join query but I want to add a 3rd join with a where clause. How do I go about doing that?

Here\'s my single join query:

var         


        
4条回答
  •  闹比i
    闹比i (楼主)
    2021-01-31 12:13

    For 4 Tables

    var query = CurrencyDeposits
    .Join(Customers, cd => cd.CustomerId, cus => cus.Id, (cd, cus) 
    => new { CurrencyDeposit = cd, Customer = cus })
    .Join(Currencies, x => x.CurrencyDeposit.CurrencyId, cr => cr.Id, (x, cr) 
    => new { x.CurrencyDeposit, x.Customer, Currency =  cr })
    .Join(Banks, x => x.CurrencyDeposit.BankId, bn => bn.Id, (x, bn) 
    => new { x.CurrencyDeposit, x.Customer, x.Currency, Bank = bn})
    .Select(s => new {
    s.CurrencyDeposit.Id,
    s.Customer.NameSurname,
    s.Currency.Code,
    s.Bank.BankName,
    s.CurrencyDeposit.RequesCode
    });
    

提交回复
热议问题