gpt4 book ai didi

c# - 运算符 '&&' 不能应用于类型 'bool' 和 'bool?' 的操作数

转载 作者:太空狗 更新时间:2023-10-29 20:44:25 30 4
gpt4 key购买 nike

<分区>

尝试读取这样的 dataContext 类

var users = new List<User>();
var roles = new int[] { 1, 2 };
// here I need to get users who's role is in role (1, 2), hence above line
// and also I need to get user who's isValid field true, please note that isValid is SQL 'bit' field and is nullable
//This is what I am doing
foreach (var user in dataContext.Users
.Where(u => roles.Contains(u.RoleID.Value)
&& u.isValid ?? false == true)) // here '&&' part I'm struggling and getting above error
{
users.Add(new User()
{
// Users Added in collection
});
}

所以问题是在 where 子句中,我需要获取角色 (1,2) && isValid == true 中的用户,如果 isValid 为“null”,则将其设为 false。谢谢

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