5

Im trying to convert a SQL Query to a linq query in vb. But Im have some trouble getting the syntax correct.

Original Query

SELECT b.* 
FROM History_Table_B b 
INNER JOIN Employee e ON b.EmployeeId = e.EmployeeId 
INNER JOIN Company c ON e.CompanyId = c.CompanyId 
WHERE e.AncillaryId = @AncillaryPersonId 
AND c.AncillaryId = @AncillaryCompanyId
AND (b.EndDate is null OR b.EndDate >= convert(date, GetDate()))

My Linq

Dim result = From b In context.H_Table_B
             Join employee In context.Employees
             On b.EmployeeId Equals (employee.EmployeeId)
             Join company In context.Companies
             On employee.CompanyId Equals (company.CompanyId) 
             Where employee.AncillaryId Equals(iPerId) 
             And company.AncillaryId Equals (iCompanyId) 
             And ((b.EndDate Is Nothing) Or (b.EndDate Equals(DateTime.Today)))

2 Answers 2

6

On where condition you can not use Equals (Operator) like Join LINQ query. Here Equals is a method of object class so you can access using '.' e.g. employee.AncillaryId.Equals(iCompanyId)

And Also one more thing in Where condition for new line VB.net required '_'.

e.g.

From b In context.H_Table_B
         Join employee In context.Employees
         On b.EmployeeId Equals (employee.EmployeeId)
         Join company In context.Companies
         On employee.CompanyId Equals (company.CompanyId) 
         Where employee.AncillaryId.Equals(iPerId) _ 
         And company.AncillaryId.Equals(iCompanyId) _
         And ((b.EndDate Is Nothing) Or (b.EndDate.Equals(DateTime.Today)))
Sign up to request clarification or add additional context in comments.

Comments

2

I think you're just missing a dot - try:

...b.EndDate.Equals(DateTime.Today)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.