title: LINQ to SQL, how can I get a count of the search terms found in a field(s)?
body: <p>Is there a way to write a query in LINQ to return the count of the search terms found in a field(s)</p>
  
  <p>Basically, I want this to work:</p>
  
  <pre><code>var matches = from t in _db.Books
                            let score = GetScore(t, searchterms)
                            where score &gt;= 1
                            orderby score descending
                            select t;
  
  public static int GetScore(Book b, params string[] searchterms)
      {
          int count = 0;
          foreach (string term in searchterms)
          {
              if (b.Title.Contains(term))
                  count++;
          }
          return count;
      }
  </code></pre>
  
  <p>But, of course, that can't work.
  Can my little GetScore function be translated into LINQ?</p>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT</strong>:  I would also prefer to have the score accessible.  Ideally I will be selecting my results into a SearchResults class (for the View) that would contain some Book info and the Book's score from the query.   To update my query, it'd be something like this:</p>
  
  <pre><code>var matches = from t in _db.Books
                            let score = GetScore(t, searchterms)
                            where score &gt;= 1
                            orderby score descending
                            select new SearchResult
                                                  {
                                                      Title = t.Title,
                                                      Type = "Book",
                                                      Link = "Books/Details/" + t.BookID,
                                                      Score = score
                                                  };
  </code></pre>
  
  <p>I'm sorry I wasn't more clear originally.</p>