I have a very simple query:
The variable ‘_dc’ is the Entity Framework Code First Data Context:
var maxLockTime = DateTime.UtcNow.AddMinutes(-1);
var record = _dc.DMPs
.Where(x =>
x.MappedId == null
&& x.Ignored == false
&& (x.ConcurrencyLockDate.Equals(null) || x.ConcurrencyLockDate < maxLockTime))
.OrderBy(x => x.id).Skip(skip).Take(1).ToList()
.Select(x => new
{
x.id,
x.Ignored,
x.MappedId,
x.SourceData
}).FirstOrDefault();
Produces the following SQL where clause:-
WHERE ([Extent1].[MappedId] IS NULL)
AND (0 = [Extent1].[Ignored])
AND ([Extent1].[ConcurrencyLockDate] < @p__linq__1)
As you can see, the “null or equals” check on ‘ConcurrencyLockDate’ is incorrect as it does not include results where it is NULL. I’m using EF5 RC with .NET 4.5 RC.
Does anyone know how I can do this? It seems so simple so I am tearing my hair out.
A column of type
DateTimecannot be null:DateTimeis a non-nullable type. If it’s nullable, the type should beDateTime?.