1

I'm creating something in ASP.NET MVC 4 and in one of my tables there is a field of type datetime. This field is defaulted to null until it is updated. I am trying select from this table the rows that have this field as null but my LINQ query always returns nothing. This is my query.

from m in this._db.MessageReadStates
where m.UserName == name
      && m.ReadDate == null
select m

I new to C# so is there a correct way to check for null?

2

1 Answer 1

6

You want to check the HasValue property of the Nullable<DateTime> type:

&& !m.ReadDate.HasValue
Sign up to request clarification or add additional context in comments.

2 Comments

Results in this warning - The given expression is never of the provided ('System.DBNull')
Edited in response to your clarification of the type in the question comments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.