Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to do a Full-Text search within a Linq query when using LLBLGen
    text
    copied!<p>[Using LLBLGen Pro 3.1 with Entity Framework 4, .NET 4 and SQLServer 2005]</p> <p>I've got a linq query that includes .Contain(keyword);</p> <pre><code> IEnumerable&lt;Product&gt; products = null; using (var context = new ModelDataContext()) { products = (from product in context.Products where product.Title.Contains(keyword) select product); } </code></pre> <p>I was looking into the performance of the query and discovered that when the SQL is generated it's actually a "like '%keyword%'" that is being generated not a contains.</p> <p>After doing a bit of research I came across some info in the LLBLGen Pro documentation regarding FunctionMapping: </p> <p><a href="http://www.llblgen.com/documentation/2.6/Using%20the%20generated%20code/Linq/gencode_linq_functionmappings.htm" rel="nofollow">http://www.llblgen.com/documentation/2.6/Using%20the%20generated%20code/Linq/gencode_linq_functionmappings.htm</a></p> <p>I've created a table-valued function on my sql database, and also the classes required within my project:</p> <pre><code> public class CustomDatabaseFunctions { public static bool FullTextSearch(string fieldToSearch, string toFind) { // empty body, as it's just here to make the query compile. The call is converted to a SQL function. return true; } } public class CustomDatabaseFunctionMappings : FunctionMappingStore { public CustomDatabaseFunctionMappings() : base() { this.Add(new FunctionMapping(typeof(CustomDatabaseFunctions),"FullTextSearch",1,"Product_FullTextSearch({0})","ProductDatabase","Resources")); } } </code></pre> <p>The next part of the documentation states that you need to pass the custom FunctionMappingStore to the LinqMetaData. In the example this is done as follows:</p> <pre><code>metaData.CustomFunctionMappings = new NorthwindFunctionMappings(); var q = from o in metaData.Order where o.CustomerId == "CHOPS" select new { o.OrderId, OrderTotal = NorthwindFunctions.CalculateOrderTotal(o.OrderId, true) }; </code></pre> <p>The problem I have is that I'm doing my linq query using the DataContext and I've no idea where the variable metaData comes from or how to use it!</p> <p>I'll keep looking to see if I can find out but any help very welcome!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload