I am some what new to LINQ so please cut me some slack.
I have a LINQ statement that I have grouped multiple columns on. Depending on the search it ranks every record with how much it matches the search.
So the First Order By is That. I then want a Thenby statement to order by FirstName
var ResultsListOrdered = from O in ResultsList
group O by new
{
O.FirstName,
O.LastName,
O.SSN,
O.Email,
O.Phone
} into g
orderby g.Max().ResultMatch descending
thenby g.Key.FirstName ascending
select new SearchResultViewModel
{
ID = g.Max().ID,
FirstName = ti.ToTitleCase(g.Key.FirstName.ToLower()),
LastName = ti.ToTitleCase(g.Key.LastName.ToLower()),
SSN = g.Key.SSN,
Email = g.Key.Email.ToLower(),
Phone = g.Key.Phone,
ResultMatch = g.Max().ResultMatch
};`
if LINQ statement works if you take out the thenby line. But as soon as you put it in it does not work.
This should work. Any help would be great
here is the error that it shows me when I hover over it
OK I AM ADDING THIS HERE FOR THE COMMENTS BELOW BECAUSE I CAN'T ADD IMAGE TO COMMENT
thenby
isn't a valid keyword, use orderby g.Max().ResultMatch descending, g.Key.FirstName ascending
.
You can see an explanation in the ThenBy operator:
In query expression syntax, an orderby [first criterion], [second criterion] (Visual C#) or Order By [first criterion], [second criterion] (Visual Basic) clause translates to an invocation of ThenBy.
I don't believe you can use thenby in this fashion its not an Keyword but extension method. In order to do what you are looking to do you would need to do this.
orderby g.Max().ResultMatch descending, g.Key.FirstName ascending
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