尝试读取DataContext类这样运算符'&&'不能应用于'bool'和'bool'类型的操作数吗?
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“空'把它弄错。 谢谢
感谢@ sudhAnsu63,但我不想过滤u.isValid == null的位置。我想获得记录,其中u.isValid == true,如果u.isValid为null(避免编译错误,将其转换为null为false) – sky 2014-10-17 14:35:22
但只返回记录,其中u.isValid == true – sky 2014-10-17 14:36:07
我已更新我的回答(第二个)。 1stOne已经按预期工作。 – sudhAnsu63 2014-10-17 14:39:16