In LINQ is it safe to carry out an inequality test on a nullable column without having to convert the nullable type?
In T-SQL you have to use ISNULL().
But in LINQ can I safely do?:
mytable.nullablecol != 1
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, it’s safe to do it that way round.
EDIT: Given your comment, the problem is probably that
null == -1has a result of null, not true (in SQL). So you could use a query of:What becomes trickier is when you want to compare for equality with a value which may be null. You have to cater for that explicitly. For example: