I am trying to use filter in the linq expression in Entity Framework. My function is:
private static DateTime GetLastDayOfQuarter(DateTime dateTime)
{
return new DateTime(dateTime.Year, dateTime.Month + 3 - dateTime.Month % 3, DateTime.DaysInMonth(dateTime.Year, dateTime.Month + 3 - dateTime.Month % 3));
}
Query:
var taskDto = await (
from task in dbContext.TbTasks
join tu in dbContext.TbTaskUsers on task.Id equals tu.Taskid
join tt in dbContext.TbTaskTypes on task.Tasktypeid equals tt.Id
where tu.Customercode == customerCode && task.Startdate < DateTime.Now &&
((task.Enddate > DateTime.Now && tu.Status == 0) || (task.Tasktypeid == 4 && task.Giftcount >= 50 && DateTime.Now < GetLastDayOfQuarter(task.Enddate)))
select new CustomerTaskDto()
{
ResponseTime = tu.Responsetime,
TaskPeriod = $"{task.Createdate} - {task.Enddate}",
TaskType = tt.Id == 4 && task.Giftcount >= 50 ? "Süper Yap Kazan" : tt.Name,
TaskTypeId = tt.Id,
EndDate = task.Enddate,
TaskId = task.Id
}).ToListAsync();
return taskDto;
I tried to call function, expression or etc on the where clause. Nothing solved the exception. Is there any possibility to call it?