Avatar of Andy Green
Andy Green
Flag for United Kingdom of Great Britain and Northern Ireland asked on

Select All with LINQ


I have the following LINQ : 

return matchingOrders.OrderBy(x => x.ProcessedDate).FirstOrDefault();

I'm struggling to change this to return All matchingOrders between 2 dates.


* LINQ.NET Programming

Avatar of undefined
Last Comment
Andy Green

8/22/2022 - Mon
Alex [***Alex140181***]

I'm afraid, we're gonna need a little more information ;-)

Might this one help already?!
Andy Green

Hi Alex, I've since changed my question. Sorry. Looking at link now. Thanks

Alex [***Alex140181***]

Ok, then the link should help you already to point you in the right direction ;-)
You'll just have to add the "where" part for filtering out the date range...
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Ryan Chong

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Fernando Soto

Hi Andy;

This line of code will only return one record,
return matchingOrders.OrderBy(x => x.ProcessedDate).FirstOrDefault();

Open in new window

To return 0 or more record change the above line to this.
return matchingOrders.OrderBy(x => x.ProcessedDate).ToList();

Open in new window

You will need to change the return type of the function to return a List<??>
Hope that helped
Andy Green

Thanks guys.