Linq 连接扩展方法的语法

Linq 连接扩展方法的语法,linq,Linq,我有下面的c代码 IQueryable query=service.GetInvoices(); query=query.Where(inv=>inv.ProjectID==ProjectID); query=query.Skip(页面索引*页面大小)。Take(页面大小); 我想使用连接扩展方法将连接添加到“Status”表中 找不到很多这样的语法示例 你能帮忙吗 加入详细信息以帮助您编写代码 联接字段为Status.ID到Invoice.invStatus 马尔科姆 var query =

我有下面的c代码

IQueryable query=service.GetInvoices();
query=query.Where(inv=>inv.ProjectID==ProjectID);
query=query.Skip(页面索引*页面大小)。Take(页面大小);
我想使用连接扩展方法将连接添加到“Status”表中

找不到很多这样的语法示例

你能帮忙吗

加入详细信息以帮助您编写代码

联接字段为Status.ID到Invoice.invStatus

马尔科姆

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);
使用联接:

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);
如果我正确理解了您的db结构,我会:

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);
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);