Asp.net mvc 使用linq到sql的高级搜索
我正在开发我的第一个ASP.net MVC应用程序,在这些应用程序中,我获得了简单而高级的搜索类型: 需要简单搜索olny dd、df和govAsp.net mvc 使用linq到sql的高级搜索,asp.net-mvc,linq,linq-to-sql,ado.net,Asp.net Mvc,Linq,Linq To Sql,Ado.net,我正在开发我的第一个ASP.net MVC应用程序,在这些应用程序中,我获得了简单而高级的搜索类型: 需要简单搜索olny dd、df和gov 高级搜索用户获得更多选项,即使在高级搜索dd、df和gov都是必填字段 这就是我的搜索行动 [HttpPost] public ActionResult search(LogModel.Search soption) { // this part will not change the same in simple and
高级搜索用户获得更多选项,即使在高级搜索dd、df和gov都是必填字段 这就是我的搜索行动
[HttpPost]
public ActionResult search(LogModel.Search soption)
{
// this part will not change the same in simple and advenced
DateTime dd1 = soption.dd;
DateTime df1 = soption.df;
var model = (from p in entity.vehicule
where p.agence.idgov == soption.gov
where !p.indisponible.Any(b => (dd1 >= b.Dd && dd1 <= b.Df) || (df1 >= b.Dd && df1 <= b.Df))
where !p.indisponible.Any(c => (c.Dd >= dd1 && c.Dd <= df1) || (c.Df >= dd1 && c.Df <= df1))
select p).ToList();
// here i want to add my filtring action advanced search
if (!soption.mark)
model = model.Any(b => b.idmarque == soption.mark );
return View(model);
}
无法将类型bool转换为Systeme.collection.generic.list模型的任何()方法返回bool。您可以尝试select()只需再次使用where子句即可
if (!soption.mark)
model = from x in model
where (b => b.idmarque == soption.mark )
select x
FirstOrDefault()将仅返回查找到的第一个数据,但我希望获取所有数据。
if (!soption.mark)
model = from x in model
where (b => b.idmarque == soption.mark )
select x