GitHub:https://github.com/fissoft/Fissoft.EntityFramework.Fts

EntityFramework中原来使用全文索引有些麻烦,需要使用DbContext.Database.SqlQuery或Execute去直接执行SQL。那样不能靠编译来检查读法错误,重构也不方便。

不过EF6增加Interceptor,可以执行前置和后置操作。

Eg:

 public class FtsInterceptor : IDbCommandInterceptor
{
#region interface impl public void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
{
} public void NonQueryExecuted(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
{
} public void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
{
} public void ReaderExecuted(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
{
} public void ScalarExecuting(DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
{ } public void ScalarExecuted(DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
{
} #endregion
}

  与Filter或其它Aop框架差不多,这里提供了一共6个方法,分别是在ScalarExecute,NonQueryExecute,ReaderExecute 这三种查询 前置及后置操作

一般来说,使用全文索引是为了查询数据,所以ScalarExecute,ReaderExecute这两种查询的前置方法需要我们改写,具体改写的原理是,将DbCommand中的CommandText读取出来,然后处理成支持全文索引的格式。

细节请参考GitHub的代码:https://github.com/fissoft/Fissoft.EntityFramework.Fts

使用时按以下方法即可

1.通过Nuget引用,或下载GitHub上的代码编译

PM> Install-Package Fissoft.EntityFramework.Fts

2.然后在程序启动时执行以下读句添加拦截器

    DbInterceptors.Init()

3.执行查询时可以使用以下几种方法

    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")));
												

Entity Framework 中使用SQL Server全文索引(Full Text Search)的更多相关文章

  1. Entity Framework Code First+SQL Server,改变聚集索引,提高查询性能

    .net Entity Framework(调研的是Entity Framework 4.0) code first方式生成数据库时,不能修改数据库表的索引,而SQLServer默认会把数据表的主键设 ...

  2. Entity Framework中执行Sql语句

           如果想在EF框架中执行Sql语句,其实很简单,EF里面已经提供了相关的方法(此处使用的EF为EF4.1版本).        EF中提供了两个方法,一个是执行查询的Sql语句SqlQue ...

  3. 在Linq to sql 和 Entity framework 中使用lambda表达式实现left join

    在Linq to sql 和 Entity framework 中使用lambda表达式实现left join 我们知道lambda表达式在Linq to sql 和 Entity framework ...

  4. Visual Studio Entity Framework (EF) 生成SQL 代码 性能查询

    Visual Studio Entity Framework (EF) 生成SQL 代码 性能查询     SQL 中,有SQL Server Profiler可以用来查询性能以及查看外部调用的SQL ...

  5. ahjesus 捕获entity framework生成的sql语句

    网上这方面的资料很少,找到一个可以用的 http://code.msdn.microsoft.com/EFProviderWrappers 里面有dll可以下载,有教程,不过是E文的. 在Entity ...

  6. [转]在Entity Framework中使用LINQ语句分页

    本文转自:http://diaosbook.com/Post/2012/9/21/linq-paging-in-entity-framework 我们知道,内存分页效率很低.并且,如果是WebForm ...

  7. SQL Server 全文索引创建

    在安装数据库管理系统SQL Server 后,默认情况下全文索引的服务是没有开启的 ,所以首先需要先开启服务,在sql server配置管理器中 (sql server configuration M ...

  8. Lazy<T>在Entity Framework中的性能优化实践

    Lazy<T>在Entity Framework中的性能优化实践(附源码) 2013-10-27 18:12 by JustRun, 328 阅读, 4 评论, 收藏, 编辑 在使用EF的 ...

  9. SQL Server 全文索引的管理

    全文索引不同于常见的聚集索引或非聚集索引,这些索引的内部实现是平衡树(B-Tree)结构,而全文索引在物理上是由一系列的内部表(Internal tables)构成的,这些内部表称作全文索引片段(Fr ...

随机推荐

  1. LINQ to SQL语句(15)之String

    LINQ to SQL支持以下String方法.但是不同的是默认情况下System.String方法区分大小写.而SQL则不区分大小写. 1.字符串串联(String Concatenation) v ...

  2. HtmlHelper拓展实现RadioList

    mvc中HtmlHelper可以帮助我们生成许多Html控件,但是没有类似DropDownList的RadioList,但是发现这些方法都是拓展方法,于是就想自己也拓展一个RadioList 从网上下 ...

  3. 从零开始编写属于我的CMS:(一)前言

    一,项目背景 记得大学毕业课题,我就是选择做个CMS,不过当时虽然做了个,不过感觉不是很好,所以现在又重做了,顺便发上来供大家讨论的.虽然CMS不是什么特别的项目,但是还是想从一个普通项目学到更多的东 ...

  4. C++实现邮件群发的方法

    这篇文章主要介绍了C++实现邮件群发的方法,较为详细的分析了邮件发送的原理与C++相关实现技巧,非常具有实用价值,需要的朋友可以参考下 本文实例讲述了C++实现邮件群发的方法.分享给大家供大家参考.具 ...

  5. 关于Spring/Hibernate 3.x升级4.x的小问题

    情景:   之前版本 现在版本 JDK 1.7 1.8 Tomcat v7.0 v8.0 Spring 3.x 4.x Hibernate 3.x 4.x MySQL 忘了 5.1.53 分析: 如果 ...

  6. 初学C++ 之 auto关键字(IDE:VS2013)

    /*使用auto关键字,需要先赋初值,auto关键字是会根据初值来判断类型*/ auto i = ; auto j = ; cout << "auto i = 5" & ...

  7. 时钟周期,CPU周期,指令周期,CPU时间片

    从小到大来说:时钟周期,CPU周期,指令周期,CPU时间片 时钟周期:一个脉冲需要的时间,频率的倒数 CPU周期:读取一个指令节所需的时间 指令周期:读取并执行完一个指令所需的时间 CPU时间片:CP ...

  8. 【Spring】浅析Spring框架的搭建

    c目录结构: // contents structure [-] Spring是什么 搭建Spring框架 简单Demo 1,建立User类 2,建立Test类 3,建立ApplicationCont ...

  9. 请将项目文件中的“AutoGenerateBindingRedirects”属性设置为 true 警告!!!

  10. Android—Bundle传递ArrayList<T>

    Android开发中Activity传值特别普遍,最贱开发需要传递集合List到另一个Activity,在此作出总结. 首先创建自己的实体类:我的暂命名为Gate. 声明List集合时候泛型中是你声明 ...