.NET Core 过滤器包含不起作用
好吧,我已经搜索过这个并找到了各种似乎是正确答案的东西,但我似乎无法让它发挥作用。我想我已经很接近了。
我已经让这段代码在我的控制器中工作,我从数据表服务器端 ajax 调用它:
var shares = await _dataService.GetAllAgencyShares();
if (!string.IsNullOrEmpty(sortColumn) && !string.IsNullOrEmpty(sortColumnDirection))
{
shares = shares.AsQueryable().OrderBy(sortColumn + " " + sortColumnDirection);
}
if (!string.IsNullOrEmpty(searchValue))
{
shares = shares.Where(m => m.FirstName == searchValue
|| m.LastName == searchValue
|| m.AgencyName == searchValue
|| m.FormId.ToString() == searchValue);
}
recordsTotal = shares.Count();
var data = shares.Skip(skip).Take(pageSize).ToList();
var jsonData = new { draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data = data };
return Ok(jsonData);
问题是我希望搜索部分
if (!string.IsNullOrEmpty(searchValue))
{
shares = shares.Where(m => m.FirstName == searchValue
|| m.LastName == searchValue
|| m.AgencyName == searchValue
|| m.FormId.ToString() == searchValue);
}
recordsTotal = shares.Count();
var data = shares.Skip(skip).Take(pageSize).ToList();
var jsonData = new { draw = draw, recordsFiltered = recordsTotal, recordsTotal =
recordsTotal, data = data };
return Ok(jsonData);
找到“类似”searchValue 的任何内容。目前这会找到完全匹配的内容。
我尝试过使用 Contains 但我相信这是布尔值。我发现的大多数东西都在使用 EF 和 IQueryable——我没有使用 EF。我尝试将 IEnumerable 转换为 Queryable ,但似乎没有任何效果。
Ok so I have searched for this and have found all kinds of things that seem to be the right answer but I cannot seem to get this working. I think I am close.
I have gotten this code to work in my controller which I call from Datatable serverside ajax:
var shares = await _dataService.GetAllAgencyShares();
if (!string.IsNullOrEmpty(sortColumn) && !string.IsNullOrEmpty(sortColumnDirection))
{
shares = shares.AsQueryable().OrderBy(sortColumn + " " + sortColumnDirection);
}
if (!string.IsNullOrEmpty(searchValue))
{
shares = shares.Where(m => m.FirstName == searchValue
|| m.LastName == searchValue
|| m.AgencyName == searchValue
|| m.FormId.ToString() == searchValue);
}
recordsTotal = shares.Count();
var data = shares.Skip(skip).Take(pageSize).ToList();
var jsonData = new { draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data = data };
return Ok(jsonData);
The problem is I would like the search part
if (!string.IsNullOrEmpty(searchValue))
{
shares = shares.Where(m => m.FirstName == searchValue
|| m.LastName == searchValue
|| m.AgencyName == searchValue
|| m.FormId.ToString() == searchValue);
}
recordsTotal = shares.Count();
var data = shares.Skip(skip).Take(pageSize).ToList();
var jsonData = new { draw = draw, recordsFiltered = recordsTotal, recordsTotal =
recordsTotal, data = data };
return Ok(jsonData);
to find anything "like" searchValue. Currently this finds exact matches.
I have tried using Contains but I believe that to be boolean. Most things I found are using EF and use IQueryable--I am not using EF. I have tried to cast IEnumerable as Queryable and nothing seems to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您究竟是如何使用
.Contains()
的?如果像这样实现的话,效果很好;
How exactly did you use
.Contains()
?It works fine if implemented like this;