I’m trying to do a join query Linq using VB. I want to return the max EnterTime, but I’m getting an error, saying “
cannot convert System.Linq.Iqueryable(Of Date) to System.Nullable(Of
Date)
How can I resolve this?
Dim results =
From b In context.H_Beneficiary
Join e In context.Employees On b.EmployeeId Equals (e.EmployeeId)
Join c In context.Companies On e.CompanyId Equals (c.CompanyId) _
Where e.IntegrationId.Equals(c.CompanyId) _
And (b.EndDate Is Nothing Or b.EndDate >= DateTime.Today)
Select b.EnterTime
You Linq query returns a sequence of dates, not a single date. That’s why the assignment won’t work.
To assign the max date from your query, you could sort the query by date, than pick the first result, if any: