此查询将仅返回 Active=true 且 Exempt=false 的所有记录。它应该返回 Active=true 且 Exempt IS NULL 的任何记录。我猜 .IsNotEqualTo 不会与任何具有空值的记录进行比较?有没有办法在不设置默认值的情况下解决这个问题?
UserCollection ActiveUsersNotExempt = new UserCollection();
ActiveUsersNotExempt = DB.Select().From<User>()
.Where(User.Columns.Active).IsEqualTo(true)
.And(User.Columns.Exempt).IsNotEqualTo(true)
.ExecuteAsCollection<UserCollection>();`
最佳答案
使用 AndExpression 如下获取嵌套约束(Exempt 不为 true 或为 null):
UserCollection ActiveUsersNotExempt = DB.Select().From<User>()
.Where(User.Columns.Active).IsEqualTo(true)
.AndExpression(User.Columns.Exempt).IsNotEqualTo(true)
.Or(User.Columns.Exempt).IsNull()
.ExecuteAsCollection<UserCollection>();`
关于c# - .IsNotEqualTo 不比较 Nulls,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/916596/