Github:https://github.com/fissoft/fissoft.entityframework.fts
EntityFramework to use full-text indexing is a bit of a hassle, you need to use DbContext.Database.SqlQuery or execute to execute SQL directly. It is not possible to compile to check the error of reading, refactoring is not convenient.
However, EF6 adds interceptor and can perform both pre-and post-operation.
Eg:
public class Ftsinterceptor:idbcommandinterceptor {#region interface Impl public void nonqueryexecuting (DbCommand command, dbcommandinterceptioncontext<int> interceptioncontext) {} public void nonqueryexecuted (DbCommand command, dbcommandinterceptioncontext<int> Intercept Ioncontext) {} public void readerexecuting (DbCommand command, Dbcommandinterceptioncontext<dbdata Reader> interceptioncontext) {} public void readerexecuted (DbCommand command, Dbcommandintercepti Oncontext<dbdatareader> interceptioncontext) {} public void scalarexecuting (DbCommand command, Dbcommandinterceptioncontext<object> interceptioncontext) {} public void Scalarexec uted (DbCommand command, dbcommandinterceptioncontext<object> interceptioncontext) {} #endregio n}
Similar to filter or other AOP frameworks, there are 6 methods available, namely three query pre-and post-operation in Scalarexecute,nonqueryexecute,readerexecute
In general, the use of full-text indexing is to query the data, so the scalarexecute,readerexecute of these two queries need us to rewrite, the specific rewriting principle is that the DbCommand in the CommandText read out, It is then processed into a format that supports full-text indexing.
For details, refer to the GitHub code: Https://github.com/fissoft/Fissoft.EntityFramework.Fts
Use the following method as follows
1. Use nuget references, or download code compilation on GitHub
Install-package Fissoft.EntityFramework.Fts
2. Then, when the program starts, execute the following read sentence to add the interceptor
Dbinterceptors.init ()
3. There are several ways you can use the query when executing
Db. Tables.where (C=>c.fullname.contains (Fulltextsearchmodelutil.contains ("code")); Db. Tables.where (C=>c.fullname.freetext (Fulltextsearchmodelutil.contains ("code EF")); Db. Tables.where (c=>"*". Contains (Fulltextsearchmodelutil.containsall ("code EF")); Db. Tables.where (c=>"*". Contains (Fulltextsearchmodelutil.freetextall ("code EF" ));
Using SQL Server full-text indexing in the Entity Framework