如何调用SvcClient中的内部联接?

时间:2017-02-08 19:14:10

标签: c# linq web-services

当我们调用webservice调用时如何插入join enties?

SELECT 
      distinct [COMMITTEE_MAST_CUST]      
  FROM [PDEV].[dbo].[COM_COMMITTEE_MEMBER] cc Inner join CUSTOMER c 
  on c.MASTER_CUSTOMER_ID = cc.COMMITTEE_MAST_CUST
  where MEMBER_MAST_CUST = '0827857' and cc.END_DATE > GETDATE()  
 and c.CUSTOMER_CLASS_CODE IN ('SECTION_OFFICER','CHAPTER_OFFICER')

但是现在这样做并不知道在上面使用上述查询将连接放在哪里。

SvcClient.Client.Context.ComCommittees.Where(x => x.MemberMasterCustomer 
        == masterCustomerId  && x.EndDate > DateTime.Today.AddMonths(-3)).ToList();

1 个答案:

答案 0 :(得分:0)

我不确定你的上下文是如何被定义的(SvcClient.Client.Context.ComCommittees对应于[PDEV]。[dbo]。[COM_COMMITTEE_MEMBER]?)但我相信你会把.Join放在前面。 Where子句。

这样的事情:

SvcClient.Client.Context.ComCommittees.Join(Customer, mast => id.COMMITTEE_MAST_CUST, cust=>cust.MASTER_CUSTOMER_ID, (mast, cust) => new { cc = mast, c = cust }).Where(x => x.MemberMasterCustomer 
        == masterCustomerId  && x.EndDate > DateTime.Today.AddMonths(-3)).ToList();

虽然你应该考虑用查询语法编写它:

var myResult = (from cc in SvcClient.Client.Context.ComCommittees
join customer in CustomerContext on cc.COMMITTEE_MAST_CUST equals customer.MASTER_CUSTOMER_ID
where (cc.MemberMasterCustomer == masterCustomerId) && (cc.EndDate > DateTime.Today.AddMonths(-3))).ToList()

(我不确定你的一些变量名,但这是基本的jist)