LINQ to SQL-检查字段长度 [英] LINQ to SQL - Checking the field length

查看:64
本文介绍了LINQ to SQL-检查字段长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Access DB获取行.我需要检查某些字段的长度.我知道了,但是问题是该字段是否为NULL.然后我的检查失败. 这是我最初通过它来检查长度的方式(array [0]是要检查的列名),并且有效:

I am getting rows from Access DB. I need to check certain fields for length. I got that to work, but the problem is if the field comes as a NULL. Then my check fails. This is how I initially made it to check for length (array[0] is a column name to be checked), and it works:

results = query.Where(p => p.Field<string>(array[0]).Length > 10);

现在的问题是该字段是否为NULL.屏幕快照显示该字段为空,但未通过我的检查.字段号为25.

Now the problem is if the field is NULL. Screen shot displays the field that is coming as empty and it fails my check. Field number is 25.

如何使它忽略空值并仍然检查长度?

How can I make it to ignore nulls and still check for length?

推荐答案

您可以尝试使用类似方法来避免null.

You can try something like this to avoid nulls.

results = query.Where(p => 
    !String.IsNullOrEmpty(p.Field<string>(array[0])) 
    &&  p.Field<string>(array[0]).Length > 10);

这篇关于LINQ to SQL-检查字段长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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