0

This is my code

public List<InvoiceJoin> ShowIvoiceList()
{
   InvoiceJoin ij = new InvoiceJoin();
   List<InvoiceJoin> list; 
   var data = (from t in _Entity.TblInvoices join t0 in _Entity.TblClients on new { ReceiverCode = t.ReceiverCode } equals new { ReceiverCode = t0.ClientCode }
   select new
   {
      t.RakeNumber,
      t.ReceiverCode,
      t.ConsigneeCode,
      t.InvoiceNumber,
      t.InvoiceDate,
      t.RecordStatus,
      t0.ClientCode,
      t0.ClientDescription,
      t0.ClientAddress1,
      t0.ClientAddress2,
      t0.ClientAddress3,
      t0.ClientCity,
      t0.ClientState,
      t0.ClientCountry,
      t0.ClientZipCode,
    }).ToList();

    foreach (var item in data)
    {
       list.Add(item);
    }
    return list;
}

my invoicejoin class

public class InvoiceJoin
{
    public TblInvoice invoice { get; set; }
    public string Cdetails { get; set; }
    public string Cname { get; set; }
    public string Caddr { get; set; }
    public string Pname { get; set; }
    public string Paddr { get; set; }
}

Its not working I need to show two sql table data list in single view how i can do this in linq pls some ne help friends i need to show in html table. . .

1
  • You can pass the returned list to the view. From view's perspective, the data is just a collection of items. Commented Jan 16, 2014 at 5:31

2 Answers 2

1

make sure that you have class InvoiceJoin with constructor which take 2 parameters: invoice and client

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

loading data:

List<InvoiceJoin> data = (from invoice in db.TblInvoices
                          join client in db.TblClients
                          on  invoice.ReceiverCode equals client.client 
                          select new{Invoice=invoice,Client=client}).ToList() 
                          .Select(n=>new InvoiceJoin(n.Invoice,n.Client)).ToList()
Sign up to request clarification or add additional context in comments.

6 Comments

ok but its not working which column i needed then that only i need to set property in invoicejoin class may i right
Ya friend its working But how can i will pass in view for example (foreach(var item in model){}) like this its not coming
How i can add 3 tables like this
The question was how to show this two tables. And it is a simple solution according with the task. But if the target goal is to show so much tables as you want, it the reason to think about implementation of dynamic dictionary for the join class. In that case it,s constructor will get objects collection and make all needed properties.
If you need just show values you may return from query anonymous type with a tuple of needed values and bind this collection directly to grid without joinclass cover
|
1

Use the LINQ Union method like this:

var data = (from t in _Entity.TblInvoices
              join t0 in _Entity.TblClients on new { ReceiverCode = t.ReceiverCode } equals new { ReceiverCode = t0.ClientCode }
              select new
              {
                  t.RakeNumber,
                  t.ReceiverCode,
                  t.ConsigneeCode,
                  t.InvoiceNumber,
                  t.InvoiceDate,
                  t.RecordStatus,
                  t0.ClientCode,
                  t0.ClientDescription,
                  t0.ClientAddress1,
                  t0.ClientAddress2,
                  t0.ClientAddress3,
                  t0.ClientCity,
                  t0.ClientState,
                  t0.ClientCountry,
                  t0.ClientZipCode,
              }).Union( // 2nd linq query with same result set as first here);

2 Comments

i Cannot Understand friend if i use union what it happened and then how can pass this list to view or bind in model and i can do in invoicejoin class
how i can join more than two tables like this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.