Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you do fulltext search with Entity Framework Core?

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.

like image 985
Daniel Avatar asked Oct 05 '18 20:10

Daniel


People also ask

Can you use EF6 with .NET core?

To use Entity Framework 6, your project has to compile against . NET Framework, as Entity Framework 6 doesn't support . NET Core. If you need cross-platform features you will need to upgrade to Entity Framework Core.

How do you use Find in EF core?

EF Core Find method finds a record with the given primary key values. If the entity is already in the context (because of a previous query), then the Find method returns it. The Find method sends the query to the database if it does not find it in the context.

How do I create a FullText index in SQL Server?

To create a full text index choose your table and right click on that table and select “Define Full-Text Index” option. Now select Unique Index. It is compulsory that for “Full Text Index” table must have at least one unique index. Select columns name and language types for columns.

Should I use EF6 or EF core?

Keep using EF6 if the data access code is stable and not likely to evolve or need new features. Port to EF Core if the data access code is evolving or if the app needs new features only available in EF Core. Porting to EF Core is also often done for performance.


1 Answers

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"));
like image 200
runxc1 Bret Ferrier Avatar answered Sep 30 '22 01:09

runxc1 Bret Ferrier