I see that Entity Framework core 2.1 has a new feature to use FREETEXT
, but I am not sure how to use it as there are no examples that I can find online.
https://github.com/aspnet/EntityFrameworkCore/issues/11484
Has anyone used it yet and could give me a quick example?
First make sure you have the relevant packages installed
Microsoft.EntityFrameworkCore
andMicrosoft.EntityFrameworkCore.SqlServer
.Then ensure you have the following import:
Now you can use the
FREETEXT
SQL function like this:Note: You can see how this works in the unit tests, for example.
To create the full text index, there is currently no support for doing this automatically in Entity Framework Core. Instead, you need to manually add the code to the migration. So, create a migration as you normally do, open it up and add lines similar to this:
Note the 2nd parameter in the call to
Sql
to suppress transactions. If you omit that you may get an error stating: