I have a LINQ query that searches for a string (using a regular expression) in multiple fields. I want to sort the results based on which field the text was found in.
I currently have this:
var results = from i in passwordData.Tables["PasswordValue"].AsEnumerable() where r.IsMatch(i.Field<String>("Key").Replace(" ","")) || r.IsMatch(i.Field<String>("Username").Replace(" ","")) || r.IsMatch(i.Field<String>("Other").Replace(" ","")) orderby i.Field<String>("Key"), i.Field<String>("Other"), i.Field<String>("Username") select i;
I want the matches to occur in Key first, then the matches found in Other, and then the matches found in Username. If possible, matches matching both Key and the other should go before matches matching only Key.
I currently have Key-based sortings, so if a match is found in Other, but Key starts with A, it will be sorted before the match found in Key, where Key starts with Z.
Thanks in advance, this is not a difficult question, I think, but I just canβt figure out how to do this, since I'm new to LINQ.
source share