2011-09-20 35 views
0

[使用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:

http://www.llblgen.com/documentation/2.6/Using%20the%20generated%20code/Linq/gencode_linq_functionmappings.htm

我已經創建了我的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查詢,我已經不知道那裏的可變元數據來自或如何使用它!

我會繼續尋找,看看我能找到,但任何幫助非常歡迎!

回答

0

你鏈接到的文檔是用於我們的框架,但你說你正在使用EFv4。所以你應該使用EF的函數映射功能,而不是我們自己的框架;)。也就是說,如果你使用EF,但是代碼表明你沒有。所以我很困惑。

在我們自己的支持論壇上發佈有關LLBLGen Pro的問題,因爲我們不監控SO。

+0

任何想法如何做到這一點?我花了一些時間搜索,但只能找到「未來」EF可能有能力映射到Table-Valued函數的事實。 – Gareth