2017-02-08 14 views
0

如何在我們調用webservice調用時插入連接內容?如何調用SvcClient中的內連接?

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

回答

0

我不知道是如何被定義的上下文(不SvcClient.Client.Context.ComCommittees對應[PDEV] [DBO]。[COM_COMMITTEE_MEMBER]?),但我相信你會放。在.WHER子句之前加入。

事情是這樣的:

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 )

+0

這個c.CUSTOMER_CLASS_CODE IN('SECTION_OFFICER','CHAPTER_OFFICER') – James123

+0

&& [「SECTION_OFFICER」,「CHAPTER_OFFICER」]。包含(customer.CUSTOMER_CLASS_CODE) – Chris