O A*_*diz 0 c# entity-framework asp.net-mvc-4
我在EF中查询了这部分内容
状态是字节.
我尝试parameters.Status.Value != 0
但对我来说它没有解决,因为0是一个值在桌子上
它下面的方式显示错误:
The result of the expression is always 'true' since the value of type 'int' is never equal to 'null' of type 'int?'
if (parameters.Status.Value != null)
{
query = query.Where(x => x.Status== parameters.Status);
}
try
{
return query
.Sort(parameters, x => x.Id)
.Paginate(parameters);
}
catch (Exception exception)
{
throw new Exception(this.context.Database.Connection.ConnectionString, exception);
}
Run Code Online (Sandbox Code Playgroud)
在我看来,如果用户没有选择任何值,它就不应该通过这个条件
obs.:没有选择值,它为null.
如何在不取0表的情况下进行此验证?
使用正确的格式检查它是否有价值
if (parameters.Status.HasValue)
{
query = query.Where(x => x.Status== parameters.Status.Value);
}
Run Code Online (Sandbox Code Playgroud)