title: Full Text Search in Linq
body: <p>There's no full text search built into Linq and there don't seem to be many posts on the subject so I had a play around and came up with this method for my utlity class:</p>
  
  <pre><code>public static IEnumerable&lt;TSource&gt; GenericFullTextSearch&lt;TSource&gt;(string text, MyDataContext context)
  {
      //Find LINQ Table attribute
      object[] info = typeof(TSource).GetCustomAttributes(typeof(System.Data.Linq.Mapping.TableAttribute), true);
      //Get table name
      String table = (info[0] as System.Data.Linq.Mapping.TableAttribute).Name;
      //Full text search on that table
      return context.ExecuteQuery&lt;TSource&gt;(String.Concat("SELECT * FROM ", table, " WHERE CONTAINS(*, {0})"), text);
  }
  </code></pre>
  
  <p>And added this wrapper to each partial Linq class where there is a full text index</p>
  
  <pre><code>public static IEnumerable&lt;Pet&gt; FullTextSearch(string text, MyDataContext context)
  {
      return (LinqUtilities.GenericFullTextSearch&lt;Pet&gt;(text, context) as IEnumerable&lt;Pet&gt;);
  }
  </code></pre>
  
  <p>So now I can do full text searches with neat stuff like</p>
  
  <pre><code>var Pets = Pet.FullTextSearch(helloimatextbox.Text, MyDataContext).Skip(10).Take(10);
  </code></pre>
  
  <p>I'm assuming only a very basic search is necessary at present. Can anyone improve on this? Is it possible to implement as an extension method and avoid the wrapper?</p>