try it
EDIT: Add DbFunctions.TruncateTime() to get the desired effect
_tareaRepositorio.ObtenerTodo() .Where( x => DbFunctions.TruncateTime(x.FechaCreacion) >= fechaInicial && DbFunctions.TruncateTime(x.FechaCreacion) <= fechaFinal) .ToList();
The exception you get is that Convert.ToDateTime is a .NET method that cannot be converted to SQL. Usually this should be done after the request has been materialized (i.e. using .ToList() before Where ), but in your particular case this is unnecessary since DateTime objects can be compared using >= and <= and the Entity Framework can successfully convert it to SQL
Now, if you want to compare only the date in Datetime, you can use the DbFunctions.TruncateTime() method, which lives in the System.Data.Entity namespace. This method will allow EF to correctly truncate the date in SQL
source share