LINQ 多条件查询怎么写?
1.页面用TextBox输入查询信息
<table>
<tr>
<td>设备编号:</td>
<td>@Html.TextBox("deviceCode")
@Html.ValidationMessage("deviceCode")
</td>
</tr>
...
<table>
2.用linq来写查询语句
[HttpPost]
public ActionResult Search(FormCollection collection)
{
var q = from p in db.Devices select p;
if (!string.IsNullOrEmpty(collection["deviceCode"]))
q = q.Where(p => p.deviceCode == int.Parse(collection["deviceCode"]));
...
return View(q.ToList());
}
最后弹出LINQ to Entities 不识别方法“Int32 Parse(System.String)”,因此该方法无法转换为存储表达式。 究竟应该怎么写多条件查询?