I have a 开发者_运维百科scenario where i have to use .Select with where in LINQ. Below is my query.
List<DTFlight> testList = _ctrFlightList.Select(i => new DTFlight() { AirLineName = i.AirLineName,ArrivalDate = i.ArrivalDate }).ToList();
I want ti use where(add condition) to this query.
Please Help... Thanks.
I suggest you this use of Where :
List<DTFlight> testList = _ctrFlightList.
Where(ctrFlight => ctrFlight.Property > 0).
Select(i => new DTFlight() { AirLineName = i.AirLineName, ArrivalDate = i.ArrivalDate }).ToList();
Where returns a IEnumerable, so you can apply your Select on it.
Simply add the Where
before the Select
:
List<DTFlight> testList =
_ctrFlightList.Where(<your condition>)
.Select(i => new DTFlight() { AirLineName = i.AirLineName,
ArrivalDate = i.ArrivalDate })
.ToList();
What is the problem?
List<DTFlight> testList = _ctrFlightList.Where(p => p.ArrivalDate > DateTime.Now).Select(i => new DTFlight() { AirLineName = i.AirLineName,ArrivalDate = i.ArrivalDate }).ToList();
for example... What condition do you need?
精彩评论