Solved

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

Posted on 2009-04-03
3
397 Views
Last Modified: 2013-11-11
my queries are

1) select * from tablename where col == null

2) select * from tablename where col  != null

i need this queries in LINQ.
0
Comment
Question by:ravindra333
3 Comments
 
LVL 21

Accepted Solution

by:
naspinski earned 250 total points
ID: 24059987

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
 
LVL 62

Assisted Solution

by:Fernando Soto
Fernando Soto earned 250 total points
ID: 24061162
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

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question