2012-09-13 158 views
0

我有這個linq查詢看起來不錯,尚未測試。 但我想知道爲什麼我不能把語句放在單獨的行上。 如果我嘗試,我得到和意外的標記錯誤,並且c和b成爲 無法訪問DUT以保護級別 工作查詢Linq查詢語法

Dim result = 
       From b In context.H_Beneficiary 
         Join e In context.Employees 
         On b.EmployeeId Equals (e.EmployeeId) 
         Join c In context.Companies 
         On e.AncillaryId Equals (c.CompanyId) 
         Where e.AncillaryId.Equals(iPerId) And c.AncillaryId.Equals(iCompanyId) And ((b.EndDate Is Nothing) Or (b.EndDate.Equals(DateTime.Today))) 
         Select b.EnterTime 


      Return CDate(result) 


     Return CDate(result) 

所需的查詢

Dim result = 
       From b In context.H_Beneficiary 
         Join e In context.Employees 
         On b.EmployeeId Equals (e.EmployeeId) 
         Join c In context.Companies 
         On e.AncillaryId Equals (c.CompanyId) 
         Where e.AncillaryId.Equals(iPerId) 
         And c.AncillaryId.Equals(iCompanyId) 
         And ((b.EndDate Is Nothing) Or (b.EndDate.Equals(DateTime.Today))) 
         Select b.EnterTime 
+0

因爲這是VB.Net語法。把'_'放在行尾,它會工作。 – asawyer

+0

@asawyer謝謝你的作品,如果你想要檢查,請在下面發帖;) –

+0

Dave的回答很好。 – asawyer

回答

3

似乎隱含的連接行唐」不要考慮'和'。 上一行只需使用一個明確的續行:

 From b In context.H_Beneficiary 
       Join e In context.Employees 
       On b.EmployeeId Equals (e.EmployeeId) 
       Join c In context.Companies 
       On e.AncillaryId Equals (c.CompanyId) 
       Where e.AncillaryId.Equals(iPerId) _ 
       And c.AncillaryId.Equals(iCompanyId) _ 
       And ((b.EndDate Is Nothing) Or (b.EndDate.Equals(DateTime.Today))) 
       Select b.EnterTime