Intersect() returns a new collection of matching elements, not bool. assuming dateOder is a collection then it is:
.Where(x => _search_datetime.Intersect(x.mp_orders.dateOrder).Count() > 0);
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I intend to compare the dates in a list with the dates in an array.
I tried to compare converting to string but without result:
string [] _search_date;
result = result.Where(x => _search_date.Contains(x.mp_orders.dateOrder.Value.ToString())).ToList();
I tried converting my string array to datetime array to intersect but with no result.:
List<DateTime?> _search_datetime = new List<DateTime?>();
foreach (string item in _search_date)
{
_search_datetime.Add(Convert.ToDateTime(item));
}
result = result.Where(x => _search_datetime.Intersect(x.mp_orders.dateOrder)).ToList();
Intersect() returns a new collection of matching elements, not bool. assuming dateOder is a collection then it is:
.Where(x => _search_datetime.Intersect(x.mp_orders.dateOrder).Count() > 0);
Hi @MiguelBT,
From your code, mp_orders.dateOrder should be of type List<DateTime?>.
You can also use the following code:
result = result.Where(x => _search_datetime.Intersect(x.mp_orders.dateOrder).Any()).ToList();
Enumerable.Any Method:Determines whether any element of a sequence exists or satisfies a condition.
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.