Search code examples
c#sql-servert-sqlentity-framework-corefull-text-search

How to write EF Core query that translates to T-SQL Contains


I have set up a full text index and the following T-SQL statement works for me in SSMS:

SELECT COUNT(*) 
FROM Person 
WHERE CONTAINS(FirstName, '"joh*"') 

But I cannot figure out how to write the equivalent query in EF Core

query.Where(p => EF.Functions.Contains(p.FirstName, $"'\"joh*\"'"));

I get an error from that code.

Can anyone help - how to do this in EF Core?


Solution

  • it seems every time I post a question, I was able to figure it out 5 mins later

    this is what worked for me

    query = query.Where(p => EF.Functions.Contains(p.FirstName, $"\"jo*\""));