我将列搜索过滤器值发送到我的 Web api,但我不知道如何使 where 子句动态化?
看下面(代码太多)!!
名称值集合:
public DataTablePager<AccountDTO> Get([FromUri] DataTableParameter param)
{
NameValueCollection nvc = HttpUtility.ParseQueryString(Request.RequestUri.Query);
转换搜索值:
if (!String.IsNullOrEmpty(nvc["sSearch_0"]) && !int.TryParse(nvc["sSearch_0"], out tmpInt) ||
!String.IsNullOrEmpty(nvc["sSearch_1"]) && !int.TryParse(nvc["sSearch_1"], out tmpInt) ||
!String.IsNullOrEmpty(nvc["sSearch_10"]) && !int.TryParse(nvc["sSearch_10"], out tmpInt)
设置 Where 子句:
filteredresults = filteredresults.Where(i => CorrectNumericTypes
&& (Lead_ID == null || i.Lead_ID == Lead_ID)
&& (Account_ID == null || i.Account_ID == Account_ID)