How to use contains (T-SQL) in Entity Framework

contains entity-framework-6 linq tsql

Question

I am looking for the equivalent of this feature of T-SQL:

SELECT * 
FROM dbo.users 
WHERE CONTAINS (name, 'Jack')

in Entity Framework.

Thanks.

P.S. "contains" in linq is equivalent of LIKE in TSQL (eg., '%jack%'). I'm not looking for this because this kind of search, especially on large databases may affect the performance.

1
1
3/22/2020 7:55:12 AM

Accepted Answer

The CONTAINS keyword is part of the full-text search capability in SQL Server - and as of this day, EF doesn't natively support full-text searching.

There are some approaches out there using EF "interceptors" or plain and simple T-SQL stored procedure to include this functionality into EF - but it's not part of the EF package provided by Microsoft.

See these other SO questions:

2
3/22/2020 8:21:53 AM

Popular Answer

In fact, In SQL, it should be

SELECT * 
FROM dbo.users 
WHERE name like '%Jack%'

And in EF, It equals to

var result = dbContext.users.Where(p => p.name.Contains("Jack")) 


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow