2014-01-16 50 views
0

這是連接查詢代碼,其中包含3個表格tblinvoice,tblClient,TblCustomer。在Tblinvoice是包含一個標誌字段中包含「客戶」然後我需要加入發票和客戶表或它包含客戶端然後我需要加入發票和客戶表我怎麼能做到這一點請幫我一些朋友。 。 。如何使用標誌字段在linq中加入多個表格

public class InvoiceJoin 
{ 
    private TblInvoice invoice; 
    private TblClient client; 
    private TblCustomer Customer; 
    public InvoiceJoin(TblInvoice invoice, TblClient client) 
    { 
     this.invoice = invoice; 
     this.client = client; 
     //this.Customer = Customer; 
     //... 
    } 
    public string RakeNumber { get { return invoice.RakeNumber; } set { invoice.RakeNumber = value; } } 
    public string partyCode { get { return invoice.ReceiverCode; } set { invoice.ReceiverCode = value; } } 
    public string invoiceNum { get { return invoice.InvoiceNumber; } set { invoice.InvoiceNumber = value; } } 
    //... ather invoice properties you want to see in grid 

    public string ClientCode { get { return client.ClientCode; } set { client.ClientCode = value; } } 
    public string ClientName { get { return client.ClientAddress1; } set { client.ClientAddress1 = value; } }   
    // ...ather clientproperties you want to see in grid 
} 

和我的數據加載方法

List<InvoiceJoin> datalist = (from invoice in _godownEntity.TblInvoices 
            join client in _godownEntity.TblClients 
            on invoice.ReceiverCode equals client.ClientCode 
            select new { Invoice = invoice, Client = client }).ToList() // until this road will be done on SQL servrer 
         .Select(n => new InvoiceJoin(n.Invoice, n.Client)).ToList(); 

回答

2

如果你問如何加入Linq中的這些表,這是語法(如果其他人,告訴在評論): 代替主和外鍵而不是在X &Ÿ

var Query = (from invoice in _godownEntity.TblInvoices 
      join client in _godownEntity.TblClients on invoice.ReceiverCode equals client.ClientCode 
      join customer in _godownEntity.TblCustomers on invoice.**X** equals customer.**Y** 
      select *WHAT U WANT* 
+0

沒有朋友,我有3代表一個是發票,然後客戶端和最後一個倉庫。在發票表中有一個字段名稱是InvoiceType在該字段中的值是1我需要加入發票和客戶表,否則我需要加入發票和倉庫表可以瞭解你的朋友 – Dinesh