显然blProject一个类的对象实现了某个类的IQueryable,假设它实现了IQueryable<BlProjectItem>:
IQueryable<BlProjectItem> blProjects = ...
显然每个 BlProjectItem 至少有三个布尔属性:
class BlProjectItem
{
public bool IsTopProject {get; set;}
public bool IsAnDesigning {get; set;}
public bool IsAnImplementation {get; set;}
...
}
您以一种困难的方式定义了三个布尔值,您的意思是:
bool top = String.IsNullOrEmpty(form["top"]));
bool design = String.IsNullOrEmpty(form["desgin"]);
bool implement = String.IsNullOrEmpty(form["implement"]);
取决于顶部/设计/实现的值是否是您想要的
Top Design Implement All BlProjectItems where
0 0 0 !IsTopProject && !IsAnDesigning && !IsAnImplementation
0 0 1 !IsTopProject && !IsAnDesigning && IsAnImplementation
0 1 0 !IsTopProject && IsAnDesigning && !IsAnImplementation
0 1 1 !IsTopProject && IsAnDesigning && IsAnImplementation
1 0 0 IsTopProject && !IsAnDesigning && !IsAnImplementation
1 0 1 IsTopProject && !IsAnDesigning && IsAnImplementation
1 1 0 IsTopProject && IsAnDesigning && !IsAnImplementation
0 1 1 IsTopProject && IsAnDesigning && IsAnImplementation
换句话说,你想要:
.Where(item => item.IsTopProject == top
&& item.IsAnDesigning == design
&& item.IsAnImplementation == implement)
你的函数会是这样的:
public ActionResult TopProjects(FormCollection form)
{
bool top = String.IsNullOrEmpty(form["top"]));
bool design = String.IsNullOrEmpty(form["desgin"]);
bool implement = String.IsNullOrEmpty(form["implement"]);
var query = blProject.Where(item => item.IsTopProject == top
&& item.IsAnDesigning == design
&& item.IsAnImplementation == implement)
// only if you don't want all properties of BlProjectItem:
.Select(item => new
{
// Select the items that you want, e.g.
Id = item.Id,
Name = item.Name,
...
});
return view(Query);
}