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
.
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.
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.
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.
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.
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"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With