检查LINQ中Field是否为空 [英] Check if Field is not null in LINQ
本文介绍了检查LINQ中Field是否为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到System.InvalidCastException
原始数据表可以有空值但在我的LINQ中我想从比较中排除这些
如何在WHERE子句中检查'not null'?
var tmpQry = FROM recOra IN dtOra 。 AsEnumerable ()
在哪里recOra 。 字段 < int ?>( " ELAPSED_RUNTIME_SECS" ) > = 4
SELECT NEW { nrecOra = recOra };
谢谢,
-srinivas y。
解决方案
你好ysrini;
试试这样var tmpQry =来自dtOra中的recOra.AsEnumerable()
其中recOra.Field< int>(" ELAPSED_RUNTIME_SECS")!= null&& recOra.Field< int>(" ELAPSED_RUNTIME_SECS")> = 4
选择新的{nrecOra = recOra};
I am getting System.InvalidCastException
The original datatable can have null values but in my LINQ I want to exclude these from comparison
How to check for 'not null' in the WHERE clause?
var tmpQry = FROM recOra IN dtOra.AsEnumerable() WHERE recOra.Field<int?>("ELAPSED_RUNTIME_SECS") >= 4 SELECT NEW { nrecOra = recOra};
Thanks,
-srinivas y.
解决方案
Hi ysrini;
Try it like thisvar tmpQry = from recOra in dtOra.AsEnumerable() where recOra.Field<int>("ELAPSED_RUNTIME_SECS") != null && recOra.Field<int>("ELAPSED_RUNTIME_SECS") >= 4 select new { nrecOra = recOra};
这篇关于检查LINQ中Field是否为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文