I'm trying to figure out a way to use methods in a SELECT query in EF Core to reduce the amount of code that is rewritten over and over again. Instead a simple method could be used to query that piece of data. The query looks like so...
var users = await DbContext.Users.Where(user => user.Id == 1)
.Select(user => new UserDTO
{
Id = user.Id,
Name = user.Name,
Unavailable = user.Tasks
.Any(task => task.HasTasksToday()),
}).ToListAsync();
The HasTasksToday() code looks like so...
public bool HasTasksToday()
{
return Tasks.Any(task => task.StartedAt.Date == DateTime.Now.Date);
}
The problem is I get a...
...could not be translated. Either rewrite the query in a form that can be translated...
...error.
I know that using IQueryable may work for this but I am unsure how that would even happen in the select statement as I know only how to use IQueryable on the Users entity.