Reputation: 109
I have DateTime variables
private readonly TimeSpan thirtydays = new TimeSpan(30, 0, 0, 0);
public DateTime RegistrationDate { get; set; }
public DateTime DueDate { get; set; }
and TimeSpan used to calculate date in the future
process.DueDate = DateTime.Now + thirtydays;
Due date can be changed during the process life. I would like to list all processes where DueDate was changed.
.Where(d => d.DueDate != (d.RegistrationDate + thirtydays))
but I get an error
InvalidCastException: Failed to convert parameter value from a TimeSpan to a DateTime.
System.Data.SqlClient.SqlCommand+<>c.<ExecuteDbDataReaderAsync>b__108_0(Task<SqlDataReader> result)
Upvotes: 4
Views: 558
Reputation: 109185
You can use
.Where(d => d.DueDate != d.RegistrationDate.AddDays(30))
In Entity Framework core this is translated into the SQL DATEADD
function.
Upvotes: 3