How to pass null values to test condition in where clause using LINQ

my queries are

1) select * from tablename where col == null

2) select * from tablename where col  != null

i need this queries in LINQ.
ravindra333Asked:
Who is Participating?
 
naspinskiConnect With a Mentor Commented:

var results1 = from p in YourDataContext.tablename where p.col == null select p;
 
var results2 = from p in YourDataContext.tablename where p.col != null select p;

Open in new window

0
 
Fernando SotoConnect With a Mentor RetiredCommented:
Hi ravindra333;

You can also use this form in Linq, The database must be a Microsoft SQL server in both solution post :

            var result1 = DataContext.TableName.Where(c => c.col  == null);
            var result2 = DataContext.TableName.Where(c => c.col  != null);

Where the c in the Where clause can be any name of your choosing.

Fernando
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.