How to execute a full text search using entity framework 6

后端 未结 2 569
小蘑菇
小蘑菇 2021-02-12 21:00

I have the query:

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

The SQL generated is:

SELECT 
...
         


        
2条回答
  •  面向向阳花
    2021-02-12 21:19

    You can use raw SQL queries with EF. So, there is another easy workaround.

            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(query).ToList();
                dataGridView1.DataSource = data;
            }
    

    Input validation etc. is omitted. Edit: Code is modified according to OP's query.

提交回复
热议问题