I expected the following LINQ query to sort according to FirstName but the OrderBy extension method seems to have no effect.
DataClassesDataContext dc = new DataClassesDataContext();
var query = from contact in dc.Contacts
select contact;
query.OrderBy(c => c.FirstName);
Everything works fine when I include the orderby in the initial query definition but I want to be able to modify it based on conditions later in my code.
Any idea why this isn't working?
try using
query = query.OrderBy(c => c.FirstName);
or
var sortedQuery = query.OrderBy(c => c.FirstName);
The OrderBy creates a new sequence.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With