我如何使用linq to sql检查底层的null值? [英] how do I check for underlying null value using linq to sql?
本文介绍了我如何使用linq to sql检查底层的null值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道,如果您查询具有空字段的linq-to-sql记录(即数据库/对象中的行),则linq to SQL将允许您访问空值而没有空引用异常,例如: Dim myValue as String = myRecord.Nullfield
.
I know that if you query a linq-to-sql record (ie row in DB/object) with a null field, then linq to SQL will allow you to access the null value without a null reference exception, like this: Dim myValue as String = myRecord.Nullfield
.
但是我想查询基础数据库中字段为空的记录.
But I WANT to query records where the field in the underlying DB is null.
如何使用LINQ做到这一点?
How do I do that with LINQ?
(From l In myDB.myTable Where l.Program.Equals(DBNull.Value) Select l).Count //Unexpected type code: DBNull
我要寻找的语法是什么?
What is the syntax that I am looking for?
推荐答案
使用== null
(或与VB.NET等效的任何东西).没有更多的DBNull
.是的!
Use == null
(or whatever the VB.NET equivalent is). No more DBNull
. Yay!
这篇关于我如何使用linq to sql检查底层的null值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文