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
  • 89
  • 8

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
  • 732,580
  • 175
  • 1,330
  • 1,459
-1

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

Matt
  • 25,943
  • 66
  • 198
  • 303
-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
  • 5,254
  • 6
  • 18
  • 28
Nguyễn Văn Phong
  • 13,506
  • 17
  • 39
  • 56