I am building a search function which needs to return a list ordered by relevance.

```
IList<ProjectDTO> projects = new List<ProjectDTO>();
projects = GetSomeProjects();

List<ProjectDTO> rawSearchResults = new List<ProjectDTO>();

//<snip> - do the various search functions here and write to the rawSearchResults

//now take the raw list of projects and group them into project number and 
//number of search returns.
//we will sort by number of search returns and then last updated date
var orderedProjects = rawSearchResults.GroupBy(x => x.ProjectNbr)
                                      .Select(x => new
                                      {
                                          Count = x.Count(),
                                          ProjectNbr = x.Key,
                                          LastUpdated = x.First().UpdatedDateTime
                                      })
                                      .OrderByDescending(x => x.Count)
                                      .ThenByDescending(x => x.LastUpdated);

```

So far so good; the "orderedProjects" variable returns my list in the correct order. However, I need the entire object for the next step. When I try to query back to get the original object type, my results lose their order. In retrospect, this makes sense, but I need to find a way around it.

```
projects = (from p in projects
            where orderedProjects.Any(o => o.ProjectNbr == p.ProjectNbr)
            select p).ToList();

```

Is there a LINQ-friendly method for preserving the order in the above projects query?

I can loop through the orderedProject list and get each item, but that's not very efficient. I can also rebuild the entire object in the original orderedProjects query, but I'd like to avoid that if possible.