tags:

views:

27

answers:

1

Hi,

I have the following c# code.

 IQueryable<Invoice> query = service.GetInvoices();

    query = query.Where(inv => inv.ProjectID == projectid);
    query = query.Skip(pageIndex * pageSize).Take(pageSize);

I want to add a Join to a "Status" table using the Join extension method.

Can't find many examples of the syntax for this.

Can you help out?

Join details to help you write the code.

Join fields are Status.ID to Invoice.invStatus

Malcolm

+1  A: 
var query = 
  (
    from i in service.GetInvoices()
    from s in service.GetStatuses()
    where i.ProjectID == projectid &&
          s.ID == i.invStatus //"join" condition here
          //add here any more where clausole you need
    select i  //you still need invoices returned?
  ).Skip(pageIndex * pageSize).Take(pageSize);

Using join:

var query = 
  (
    from i in service.GetInvoices()
    join s in service.GetStatuses() on s.ID equals i.invStatus
    where i.ProjectID == projectid 
          //add here any more where clausole you need
    select i  //you still need invoices returned?
  ).Skip(pageIndex * pageSize).Take(pageSize);

If I understood your db structure correctly I would go for:

var query = 
  (
    from i in service.GetInvoices()
    from s in i.Status      //get all the statuses associated to this invoice
    where i.ProjectID == projectid 
          //add here any more where clausole you need
    select i  //you still need invoices returned?
  ).Skip(pageIndex * pageSize).Take(pageSize);
Alex Bagnolini