我希望使用LINQ表达式
获得列值为NULL的结果search.AddCriteria(x => x.LogStatus ==
Inventory.AffStatusToChar((EAffidavitLogStatus)byte.Parse(cmbLog.SelectedValue)));
public void AddCriteria (Expression<Func<T, bool>> criteria) {
if (_where == null) { _where = w => true; }
_where = And(criteria);
}
private Expression<Func<T, bool>> And (Expression<Func<T, bool>> expr) {
return Expression.Lambda<Func<T, bool>>(Expression.And(
_where.Body,
Expression.Invoke(expr, _where.Parameters.Cast<Expression>())
), _where.Parameters);
}
//This below part is use to execute the Linq
//IQueryable<T> result = db.GetTable<T>();
//result = result.Where(_where);
结果是部分看起来像WHERE ([t0].[LogStatus]) = @p5)
看我想要IS NULL
我想要这样的查询
SQL query : `select * from xyz where abc is NULL`
但上面的LINQ表达式正在转换为
select * from xyz where abc=NULL
会产生不同的结果。
任何一个经历过这种问题的人? LINQ表达式中IS NULL
如何实现这一目标?
答案 0 :(得分:0)
没关系,我自己认为这就是我所做的解决方案
search.AddCriteria(x => !(x.LogStatus!=null));
这会返回类似
的查询WHERE (NOT (UNICODE([t0].[LogStatus]) IS NULL ))
多田!!这就是我所期待的......
答案 1 :(得分:0)
嘿,你可以查看这篇文章(Linq and Nullable Values) OR ( SQL ISNULL with LINQ)
你可以尝试
var user = from u in Users
join uc in UserClients on u.Id equals uc.UserId
into myuserwithclient
from m in myuserwithclient.DefaultIfEmpty()
select new {
Id=u.Id,
FirstName=u.FirstName,
LastName=u.LastName,
UserId=m.UserId,
MobileNo = m.MobileNo ?? "N/A"
};
var nullvalues = user.where( u=>u.MobileNo== "N/A");