1 回答
TA贡献1827条经验 获得超4个赞
如果使用Like(w.GetProperty(item.Value), ...)
,则请求在客户端上执行,而不是在服务器上执行。要将整个请求发送到服务器,您可以执行以下操作:
List<WorkerTableRow> Search(ItemSearch item, string text)
{
string pattern = string.Format("%{0}%", text);
using (var model = new ModelContext())
{
IQueryable<Worker> query = model.Workers;
if (item.Value == "FullName")
query = query.Where(w => EF.Functions.Like(w.FullName, pattern));
if (item.Value == "PassportSeries")
query = query.Where(w => EF.Functions.Like(w.PassportSeries, pattern));
if (item.Value == "PassportNumber")
query = query.Where(w => EF.Functions.Like(w.PassportNumber, pattern));
return query.Select(w => new WorkerTableRow { ... }).ToList();
}
}
- 1 回答
- 0 关注
- 117 浏览
添加回答
举报