[使用LLBLGEN Pro的3.1與實體框架4,.NET 4和SQLServer 2005]如何使用LLBLGEN
我有一個LINQ查詢,包括.Contain時候做一個LINQ查詢中的全文搜索(關鍵詞);
IEnumerable<Product> products = null;
using (var context = new ModelDataContext())
{
products = (from product in context.Products where product.Title.Contains(keyword)
select product);
}
我一直在尋找到查詢的性能,發現所生成的SQL時,它實際上是一個「像‘%關鍵字%’」正在生成不包含。
做了一些研究之後,我整個LLBLGEN專業文檔中的一些信息來關於FUNCTIONMAPPING:
我已經創建了我的SQL數據庫中的表值函數,也是類我的項目中需要:
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"));
}
}
文件的下一部分規定您需要自定義FunctionMappingStore傳遞給LinqMetaData。在本例中此如下進行:
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) };
我的問題是,我使用的DataContext做我的LINQ查詢,我已經不知道那裏的可變元數據來自或如何使用它!
我會繼續尋找,看看我能找到,但任何幫助非常歡迎!
任何想法如何做到這一點?我花了一些時間搜索,但只能找到「未來」EF可能有能力映射到Table-Valued函數的事實。 – Gareth