Reputation: 363
I have the following query:
SELECT Animals.name
FROM Animals
WHERE CONTAINS(*, 'feline AND black');
I am having trouble converting it to an Entity Framework Core query. I have a SQL Server with a catalog that has a few indexes.
I want to be able to use FREETEXT
and CONTAINS
to do a fulltext query on the tables. I cannot find the method in Entity Framework Core for fulltext search with CONTAINS
.
Upvotes: 11
Views: 19501
Reputation: 73
Yes it is posible using EF 6, just use EF.Functions.Contains
var results = db.Widgets
.Where(x => EF.Functions.Contains(x.ColumnName, "search text"));
Important "search text" do not allow blank spaces you have to separate each word using logic operators like AND OR, for example if you want to search records with "green" and "blue", you have to put "green AND blue", not "green blue"
Upvotes: 5
Reputation: 8233
This is possible as of EF Core 2.1. You have to add a using statement for Microsoft.EntityFrameworkCore but after that you can use it as shown below
var results = db.Widgets
.Where(x => EF.Functions.FreeText(x.ColumnName, "search text"));
Upvotes: 27