Open Lesterdor opened 3 years ago
@Lesterdor try:
(from employee in ctx.Employees
from absence in ctx.Absences.Where(x => x.EmployeeId == employee.Id && x.Status == Status.Accepted && x.From >= date).DefaultIfEmpty()
where employee.Id == employeeId && (absence == null || date <= absence.From)
select new { E = employee, A = absence }).FirstOrDefaultAsync();
this generates:
SELECT TOP(1) [e].[Id], [t].[Id], [t].[EmployeeId], [t].[From], [t].[Status]
FROM [Employees] AS [e]
LEFT JOIN (
SELECT [a].[Id], [a].[EmployeeId], [a].[From], [a].[Status]
FROM [Absences] AS [a]
WHERE ([a].[Status] = 0) AND ([a].[From] >= @__date_0)
) AS [t] ON [e].[Id] = [t].[EmployeeId]
WHERE ([e].[Id] = @__employeeId_1) AND ([t].[Id] IS NULL OR (@__date_0 <= [t].[From]))
Hey,
I have a valid SQL-Statement which I would like to translate into LINQ query syntax:
I would like to be flexible with regard to the date, which is why I want to control it via method's parameter 'date'. But I get the following message:
If I change
into
In other words, If I don't use the method's parameter everything works fine. But I need to control the date via a parameter. Is that a bug or how can I achieve that?
I am using Microsoft.EntityFrameworkCore 5.0.1
Many thanks in advance! -Lesterdor