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)))
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)))
I think you're just missing a dot - try:
...b.EndDate.Equals(DateTime.Today)