1

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.

Amir Parsi
  • 93
  • 6

3 Answers3

2

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:

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
-1

I think it's just users.Where(x => x.name.Contains("jack"));

Matt
  • 24,866
  • 63
  • 189
  • 295
-1

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")) 
Selim Yildiz
  • 4,978
  • 6
  • 16
  • 25
Nguyễn Văn Phong
  • 12,566
  • 16
  • 32
  • 51