Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello there,

In SQL query we have isNull function How we can implement that in LINQ.
Ex :
SQL
SELECT isNull(Qty,0) FROM BillMain


What will be the LINQ for the SQL query?
Posted
Comments
_Amy 26-Jun-13 4:42am    
Can I see your query?

Please check this
C#
var result= from b in BillMain select new{Qty=(b.Qty==DBNull.value ? 0:b.Qty)}
 
Share this answer
 
Try this.

C#
var result = from b in BillMain
             select new
             {
                 Qty =b.Qty ?? 0
             }
 
Share this answer
 
You should try something like this:
C#
var orders =  from o in db.Orders select new {
    OrderID = o.OrderID == DBNull.Value ? 0 : o.OrderID, //Checking for null value and passing 0 if null
    o.CustomerID,
    o.EmployeeID,
    o.ShippedDate
}




--Amit
 
Share this answer
 
Comments
The Doer 26-Jun-13 5:17am    
yelo bhai, tumare liye mera chota sa tofa-
http://www.codeproject.com/Questions/372390/How-to-insert-the-correct-range-in-sql-server
_Amy 26-Jun-13 5:35am    
XML
YourContext db = new YourContext();

List<entity> list =  (from n in db.YourEntity
                     where n.FieldToCheck.Equals(null)
                     select n).ToList();
 
Share this answer
 
Read This ...may be it is Helpful 2 u:)

SQL
from c in dtx.Categories
where c.CategoryId == CatId
    && (string.IsNullOrEmpty(param1) || c.Param1 == param1)
    && (string.IsNullOrEmpty(param2) || c.Param2 == param2)
select c
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900