Linq C中的Nullable Type# [英] Nullable Type In Linq C#

查看:75
本文介绍了Linq C中的Nullable Type#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据库中有一些行为null,我如何使用可空类型或如何在linq中跳过可空行?但我更喜欢使用可空类型而不是跳过行

in my database there is some row which is null and how can i use nullable type or how can i skip nullable row in linq? but i prefer to use nullable type rather than skip rows

推荐答案

什么类型的数据库例如。 SQL-Server?

What type of database eg. SQL-Server?

用于读取数据的方法,例如。实体框架,SqlClient托管提供者进入DataTable ???

What method is used to read data eg. Entity Framework, SqlClient managed provider into a DataTable???

也许没有DataTable而是使用DataReader

Perhaps no DataTable but instead using a DataReader

if (read.Read())
{
   int colIndex = read.GetOrdinal("MyColumnName");
   maskedTextBox2.Text = read.IsDBNull(colIndex) ? 
                  string.Empty : 
                  read.GetDateTime(colIndex).ToString("MM/dd/yyyy");

}

使用LINQ

var query1 =
    from c in categories
    where c != null
    join p in products on c.ID equals
        p?.CategoryID
    select new { Category = c.Name, Name = p.Name };


这篇关于Linq C中的Nullable Type#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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