0

[Using LLBLGen Pro 3.1 with Entity Framework 4, .NET 4 and SQLServer 2005]

I've got a linq query that includes .Contain(keyword);

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

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.

After doing a bit of research I came across some info in the LLBLGen Pro documentation regarding FunctionMapping:

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

I've created a table-valued function on my sql database, and also the classes required within my project:

    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"));
    }
}

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:

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) };

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!

I'll keep looking to see if I can find out but any help very welcome!

Gareth
  • 33
  • 1
  • 6

1 Answers1

0

the documentation you're linking to is for our framework, yet you're saying you're using EFv4. So you should use the function mapping feature of EF, not our own framework ;). That is, if you're using EF, but the code suggests you don't. So I'm very confused.

It's also better to post questions about LLBLGen Pro on our own support forums as we don't monitor SO.

Frans Bouma
  • 8,259
  • 1
  • 27
  • 28
  • Any idea how this is done? I've spent some time searching but can only find references to the fact that 'in the future' EF may have the ability to map to Table-Valued functions. – Gareth Sep 21 '11 at 09:25