NibblyPig
NibblyPig

Reputation: 52952

Make Entity Framework use Contains instead of Like and explain 'ESCAPE ~'

I have a line of LINQ that im using in EF which is basically doing myTable.Where(c => c.Contains('mystring'));

This is the generated code:

SELECT TOP (300) 
[Extent1].[ID] AS [ID], 
[Extent1].[FKFishEntityID] AS [FKFishEntityID], 
[Extent1].[Fish] AS [Fish], 
[Extent1].[FishText] AS [FishText], 
[Extent1].[FishType] AS [FishType]
FROM [dbo].[Fish] AS [Extent1]
WHERE [Extent1].[FishText] LIKE @p__linq__0 ESCAPE '~'

My two questions are:

Upvotes: 8

Views: 2269

Answers (1)

Lorentz Vedeler
Lorentz Vedeler

Reputation: 5311

from the [entity framework blog]:1

There is no native support for full-text search planned at the moment. You would need to use a raw SQL query.

Seems that the way to go is something like this:

using (var context = new BloggingContext())
{
    var fishes = context.Fishes.SqlQuery("SELECT * FROM dbo.Fishes WHERE CONTAINS(FishText, @p0)", searchPhrase).ToList();
}

Upvotes: 4

Related Questions