gpt4 book ai didi

c# - 如何将 DBNull 检查到 linq 或 int32?

转载 作者:行者123 更新时间:2023-11-30 22:18:35 25 4
gpt4 key购买 nike

我想获取 CategoryIdnull 的所有行。我写了下面的代码,但它给了我错误

" Operator ' == ' can not applied to operands of type 'int?' and System.DBNull

   public Nullable<Int32>  CategoryId { get; set; }
Game objGame;
var query = (from gametypebygametype in db.GameByGameTypes.Where(x => x.CategoryId == DBNull.Value)
join game in db.Games
on gametypebygametype.GameId equals game.GameId into joined
from game in joined.DefaultIfEmpty()
select new
{
game.GameId,
game.GameName
}
).Distinct();
List<Game> objlistGame = new List<Game>();
foreach (var item_temp in query)
{
objGame = new Game();
objGame.GameId = item_temp.GameId;
objGame.GameName = item_temp.GameName;
objlistGame.Add(objGame);
}

最佳答案

尝试只使用 null 而不是 DBNull.ValueHasValue = false

关于c# - 如何将 DBNull 检查到 linq 或 int32?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16009471/

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