Writing a write request using Linq on VB.net

I am trying to convert a SQL query to a linq query in vb. But I have some problems with the syntax rule.

Original request

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))) 
+4
source share
2 answers

In what state you cannot use Equals (Operator), for example, Join LINQ query. Here, Equals is an object class method, so you can access using '.' e.g. employee.AncillaryId.Equals(iCompanyId)

And one more thing is where the condition for the new line of VB.net requires "_".

eg.

 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))) 
+5
source

I think you are just missing the point - try:

 ...b.EndDate.Equals(DateTime.Today) 
+2
source

Source: https://habr.com/ru/post/1434036/


All Articles