LINQ是Null函数 [英] LINQ isNull function

查看:50
本文介绍了LINQ是Null函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



在SQL查询中我们有isNull函数我们如何在LINQ中实现它。

Ex:

Hello there,

In SQL query we have isNull function How we can implement that in LINQ.
Ex :

SELECT isNull(Qty,0) FROM BillMain





SQL查询的LINQ是什么?



What will be the LINQ for the SQL query?

推荐答案

请检查这个

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


试试这个。



Try this.

var result = from b in BillMain
             select new
             {
                 Qty =b.Qty ?? 0
             }


你应该尝试这样的事情:

You should try something like this:
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


这篇关于LINQ是Null函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆