i am trying to return queries from a DB using Entity Framework and Linq on a Nullable DateTime field.
I have the following code;
DateTime? from = new DateTime(year, month, 1);
DateTime? to = from.Value.AddMonths(1);
return context.Where<Job>(
x =>
x.NextDueDate?.Date >= from?.Date &&
x.NextDueDate?.Date <= to?.Date).ToList();
Where Job is (reduced for brevity);
public class Job : AuditableEntity
{
...
public DateTime? NextDueDate { get; set; }
I tried this from the following stack link;
Linq expression with nullable DateTime
However, when I try this I am getting the following error;
An expression tree lambda may not contain a null propagating operator
Can anyone explain a solution to this please?
As the exception message said you cannot use
?
.