让实体框架使用含而不象和解释“ESCAPE〜” [英] Make Entity Framework use Contains instead of Like and explain 'ESCAPE ~'

查看:109
本文介绍了让实体框架使用含而不象和解释“ESCAPE〜”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有LINQ的线路使用EF这基本上是做,即时通讯 myTable.Where(C => c.Contains('了mystring'));

I have a line of LINQ that im using in EF which is basically doing myTable.Where(c => c.Contains('mystring'));

这是生成的代码:

SELECT TOP (300) 
[Extent1].[ID] AS [ID], 
[Extent1].[FKFishEntityID] AS [FKFishEntityID], 
[Extent1].[Fish] AS [Fish], 
[Extent1].[FishText] AS [FishText], 
[Extent1].[FishType] AS [FishType]
FROM [dbo].[Fish] AS [Extent1]
WHERE [Extent1].[FishText] LIKE @p__linq__0 ESCAPE '~'

我的两个问题是:


  • 我如何让它使用contains(...),而不是什么样的?看来,喜欢的是非常缓慢当表使用全文索引。复制和粘贴查询它需要4秒执行,但如果我改变喜欢CONTAINS()它执行瞬间。

  • How do I make it use CONTAINS(...) instead of LIKE? It seems that LIKE is very slow when the table is using full text indexing. Copying and pasting the query it takes 4 seconds to execute, but if I change LIKE to CONTAINS() it executes instantly.

为什么会这样ESCAPE'〜 '?通过复制+粘贴到SQL服务器这一点,它执行绕快4倍,如果我删除了逃离的一部分。

Why does it do ESCAPE '~' ? By copying + pasting this into SQL server, it executes around 4 times faster if I remove the 'ESCAPE' part.

推荐答案

从[实体框架博客]:的 1

from the [entity framework blog]:1

有针对全文检索没有原生支持计划眼下。你将需要使用原始的SQL查询

There is no native support for full-text search planned at the moment. You would need to use a raw SQL query.

似乎是要走的路是这样的:

Seems that the way to go is something like this:

using (var context = new BloggingContext())
{
    var fishes = context.Fishes.SqlQuery("SELECT * FROM dbo.Fishes WHERE CONTAINS(FishText, @p0)", searchPhrase).ToList();
}

这篇关于让实体框架使用含而不象和解释“ESCAPE〜”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆