小编Hen*_*nry的帖子

使用实体框架核心进行全文搜索

使用EFCore进行全文搜索的最佳方法是什么

现在我有两种方法

方法#1

 var entities = this.DbContext.Example
            .FromSql("fullText_Proc {0}, {1}", searchTermParameter, topParameter);

        return entities.AsNoTracking().ToList();
Run Code Online (Sandbox Code Playgroud)

在这里,我被迫创建一个proc,因为FromSql忽略了WHERE子句.

方法#1

创建命令并手动执行映射

using (var command = this.DbContext.Database.GetDbConnection().CreateCommand())
    {
        command.CommandText = "SELECT ... WHERE CONTAINS("Name", @p1)";
        command.CommandType = CommandType.Text;
        var parameter = new SqlParameter("@p1",...);

        this.DbContext.Database.OpenConnection();

        using (var result = command.ExecuteReader())
        {
            while (result.Read())
            {
               .... // Map entity
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

c# entity-framework-core .net-core

7
推荐指数
1
解决办法
3081
查看次数

标签 统计

.net-core ×1

c# ×1

entity-framework-core ×1