Как создать запрос для фильтрации таблицы из базы данных, когда некоторые переданные значения равны нулю или пусты ?
Hi C# Core Teams Developer could you please help me with a query Table result will be loaded by ajax on Razor page Table A from data base to filter and create result to display +------------+-----------+-------+ | StartDate | EndDate | Name | +------------+-----------+-------+ | 05/11/2019 |05/12/2019 | Smith | +------------+-----------+-------+ | 01/12/2019 |05/12/2019 | Tom | +------------+-----------+-------+ | 04/08/2019 |05/11/2019 | Dante | +------------+-----------+-------+ public JsonResult FilterTableA ( string dateStart, string dateEnd, string name) { var createFilter = await _context.TableA .Where(r => (r.CreatedDate >= dateStart && r.UpdatedDate <= dateEnd && r.UserName == name) .ToLis(); return new JsonResult(createFilter ); } Thanks Everyone!!!!
Что я уже пробовал:
these are input fields in page to create the filter: but user can just type the name and search in database Table A and create the filter or user can type fromDate >= or user can type toDate >= or user can type toDate and the UserName and do the filter I dont know how to include this options in the query??? +------------+-----------+ |From date |05/11/2019 | +------------+-----------+ +------------+-----------+ | To Date |05/11/2019 | +------------+-----------+ +------------+-----------+ | Name | Dante | +------------+-----------+ Just filter by Name: +------------+-----------+ |From date | | +------------+-----------+ +------------+-----------+ | To Date | | +------------+-----------+ +------------+-----------+ | Name | Dante | +------------+-----------+ result of search filter: +------------+-----------+-------+ | StartDate | EndDate | Name | +------------+-----------+-------+ | 04/08/2019 |05/11/2019 | Dante | +------------+-----------+-------+ How could I create the sql query to filrter Table A in database var createFilter = await _context.TableA Where(r=> (r.CreatedDate == null r.UpdatedDate == null r.UserName == name) || (r.UpdatedDate <= dateEnd && r.UserName == name) ).ToLis();