Make sure that lowdate
is at least 1/1/1753.
If you try to supply a date prior to that, EF will convert it, and pass it into your query. In addition, you need to not use DateTime.MinValue
in the query, but rather what would be your min:
DateOfBirth = ((s.Date_Of_Birth == null) || (s.Date_Of_Birth <= lowdate)) ?
new DateTime(1753,1,1) : s.Date_Of_Birth.Value;
Remember, with EF, the query gets compiled and converted to SQL on the server, so the values must all be appropriate there, as well.
That being said, I'd personally prefer to store DateOfBirth
as DateTime?
(nullable type) instead of using a "magic value" (DateTime.MinValue
) to hold database null or inappropriate values.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…