2014-09-12 17 views
17

ho la query:Come eseguire una ricerca full text utilizzando Entity Framework 6

var query = DataContext.Fotos.Where(x => x.Pesquisa.Contais("myTerm") 

L'SQL generato è:

SELEZIONA ... DA Fotos AS [Extent1] . WHERE [Extent1] [Pesquisa] COME N '% mytem%'

ma ho bisogno di usare:

SELEZIONA ... DA Fotos AS [Extent1] WHERE CONTAINS ([Extent1]. [Pesquisa], 'il mio mandato')

Come eseguire una ricerca a testo integrale utilizzando Entity Framework 6?

+0

http://www.mikesdotnetting.com/article/298/implementing-sql-server-full-text-search-in-an-asp-net-mvc-web-application-with-entity-framework –

risposta

19

Sembra che Entity Framework 6 non supporti la ricerca full-text, ma esiste una soluzione alternativa con gli intercettori.

http://www.entityframework.info/Home/FullTextSearch

+1

Come posso farlo funzionare con l'approccio Database First? –

+0

Vorrebbe anche sapere come farlo funzionare con un primo approccio al database –

0

È possibile utilizzare query SQL prime con EF. Quindi, c'è un'altra soluzione facile.

 using (DBContext context = new DBContext()) 
     { 
      string query = string.Format("Select Id, Name, Description From Fotos Where CONTAINS(Pesquisa, '\"{0}\"')", textBoxStrToSearch.Text); 
      var data = context.Database.SqlQuery<Fotos>(query).ToList(); 
      dataGridView1.DataSource = data; 
     } 

La convalida dell'input è omessa. Modifica: il codice viene modificato in base alla query dell'OP.

Problemi correlati