【发布时间】:2015-11-24 21:13:43
【问题描述】:
我在 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);
}
在我看来 如果用户没有选择任何值,它不应该通过这个条件如果
obs .: 没有选择它是空值。
如何在不取 0 表的情况下进行此验证?
【问题讨论】:
-
也许你应该检查
parameters.Status.Value != 0而不是null? -
那个输入参数可以像'int?状态'
-
请显示
parameters是其实例的类的代码。
标签: c# entity-framework asp.net-mvc-4