-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
  • 732,580
  • 175
  • 1,330
  • 1,459
Sevval Kahraman
  • 1,185
  • 3
  • 10
  • 37

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
  • 13,506
  • 17
  • 39
  • 56