Home » c# » DateTime TryParse in lambda query c#

DateTime TryParse in lambda query c#

Posted by: admin February 21, 2020 Leave a comment

Questions:

I want use DateTime.TryParse in lambda query. It is not working as i am doing.
I am try to filter data from flight collection and using TryParse to parse datetime if parsing will be success then we will filter data from range if it will not parse then we will use schedule time instead of that.

flights.Where(x => (x.ADI.Equals(FlightADI.Arrival)
                                    && DateTime.TryParse(x.getFieldValue(StandardFightXMLFeedConfiguration.Current.MostConfident_Arrival),
                                     out dtarr)
                                    && dtarr != DateTime.MinValue ? (dtarr > rangeStart && dtarr < rangeEnd) :
                                     (x.Scheduled > rangeStart && x.Scheduled < rangeEnd))
                                    || (x.ADI.Equals(FlightADI.Departure)
                                    && DateTime.TryParse(x.getFieldValue(StandardFightXMLFeedConfiguration.Current.MostConfident_Departure),
                                     out dtdep)
                                    && dtdep != DateTime.MinValue ? (dtdep > rangeStart && dtdep < rangeEnd) :
                                     (x.Scheduled > rangeStart && x.Scheduled < rangeEnd))).ToList();
How to&Answers: