-2

I wrote this query, but I want to use it with functions.

var hede = (from customer in _customerRepository.Table
            join source in _sourcedefinitionepository.Table on customer.SouceCode equals source.SourceCode
            join branch in _branchdefinitionepository.Table on customer.BranchCode equals branch.BranchCode
            where customer.SirketKod == 1 && source.UretimKanali == "E"
            select new { Customer = customer, SourceName = source.LongName, branch.BranchName});

How can I join 3 tables, how can I convert this code?

var query = _customerRepository.Table.Join() ... Select()...

Thank you.

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
Sevval Kahraman
  • 948
  • 3
  • 8
  • 25

1 Answers1

1

You can achieve it in this way

var result2Tables = _customerRepository.Table.Join(_sourcedefinitionepository.Table, c => c.SouceCode , s => s.SourceCode,
                (c, s) => new
                {
                    Customer = c, 
                    SourceName = s
                })).Where(p => p.Customer.SirketKod == 1 && p.SourceName .UretimKanali == "E")

var result = result2Tables.Join(_branchdefinitionepository.Table, p => p.Customer.BranchCode, b => b.BranchCode, (r, b) => new 
   {
      Customer = r, 
      SourceName = r.SourceName.LongName, 
      b.BranchName 
   }) 
Nguyễn Văn Phong
  • 12,566
  • 16
  • 32
  • 51