Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core 如何将where子句应用于现有的IEnumerable<;模型>;用于对记录进行增量筛选_Asp.net Core_Controller - Fatal编程技术网

Asp.net core 如何将where子句应用于现有的IEnumerable<;模型>;用于对记录进行增量筛选

Asp.net core 如何将where子句应用于现有的IEnumerable<;模型>;用于对记录进行增量筛选,asp.net-core,controller,Asp.net Core,Controller,我试图通过有条件地从控制器中提供where子句来过滤记录。我的记录列表是IEnumerable list。如何给IEnumerable指定where条件。 这是我的密码 public IActionResult UniformIssueList(UniformDeliveryVM uniformDeliveryVM) { var issuesList = _unitOfWork.UniformReceiptRepo.GetUniformDeliveryList(uniformD

我试图通过有条件地从控制器中提供where子句来过滤记录。我的记录列表是IEnumerable list。如何给IEnumerable指定where条件。 这是我的密码

    public IActionResult UniformIssueList(UniformDeliveryVM uniformDeliveryVM)
{
     var issuesList = _unitOfWork.UniformReceiptRepo.GetUniformDeliveryList(uniformDeliveryVM.FromDate, uniformDeliveryVM.ToDate);
         if (uniformDeliveryVM.DepotNo>=0)
         {
           issuesList  = issuesList.Where(d => d.DepotNo == uniformDeliveryVM.DepotNo
         }
     if (uniformDeliveryVM.DepartmentNo >=0)
         {
           issuesList  = issuesList.Where(d => d.DepartmentNo == uniformDeliveryVM.DepartmentNo
         }
          if (uniformDeliveryVM.EmployeeId >=0)
         {
           issuesList  = issuesList.Where(d => d.EmployeeId == uniformDeliveryVM.EmployeeId
         }
}

事实上,您的想法是正确的,您只需要在Where条件之后添加Tolist()

像这样:

if (uniformDeliveryVM.DepotNo >= 0)
            {
                issuesList = issuesList.Where(d => d.DepotNo == uniformDeliveryVM.DepotNo).ToList();
            };
            if (uniformDeliveryVM.DepartmentNo >= 0)
            {
                issuesList = issuesList.Where(d => d.DepartmentNo == uniformDeliveryVM.DepartmentNo).ToList();
            }
            if (uniformDeliveryVM.EmployeeId >= 0)
            {
                issuesList = issuesList.Where(d => d.EmployeeId == uniformDeliveryVM.EmployeeId).ToList();
            }
希望这能帮助你