0

[Entity Framework 4、.NET 4、SQLServer 2005 で LLBLGen Pro 3.1 を使用]

.Contain(keyword); を含む linq クエリがあります。

    IEnumerable<Product> products = null;
    using (var context = new ModelDataContext())
    {
    products = (from product in context.Products where product.Title.Contains(keyword)
     select product);
    }

クエリのパフォーマンスを調べていたところ、SQL が生成されると、実際には "like '%keyword%'" が生成され、contains ではないことがわかりました。

少し調査した後、LLBLGen Pro のドキュメントで 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 クエリを実行していて、変数 metaData がどこから来ているのか、またはその使用方法がわからないことです!

私は見つけることができるかどうかを確認し続けますが、どんな助けも大歓迎です!

4

1 に答える 1

0

リンクしているドキュメントはフレームワーク用ですが、EFv4を使用していると言っています。したがって、独自のフレームワークではなく、EFの関数マッピング機能を使用する必要があります;)。つまり、EFを使用しているが、コードは使用しないことを示唆している場合です。だから私はとても混乱しています。

また、SOを監視していないため、LLBLGenProに関する質問を独自のサポートフォーラムに投稿することをお勧めします。

于 2011-09-20T21:04:16.847 に答える