gpt4 book ai didi

asp.net - 检查 Entity Framework 中 Linq 查询中的空值

转载 作者:行者123 更新时间:2023-12-05 01:28:31 27 4
gpt4 key购买 nike

如何比较整数类型的空值 .Net Entity framework 4.1 中 Linq 查询的 Where 部分?

最佳答案

您只能比较 intNULL如果 intnullable .如果不是,int 的默认值将是 0永远不会null .

您可以像这样定义一个可为空的 int 属性:

int? value { get; set; }

并像这样检查它:
if ( value != null )
{
int x = value.Value;
}

在 Linq 查询的 where 子句中,它将是
var result = from d in data
where d.Value != null
select d

关于asp.net - 检查 Entity Framework 中 Linq 查询中的空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8912946/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com