-1

I am using EF and trying generate query with LIKE operator.

query = query.Where(x => x.MobilePhone.Contains(mobilePhone));

This block generates this query.

-- @__mobilePhone_0='42534'
SELECT *
FROM customers AS c
WHERE (@__mobilePhone_0 = '') OR (strpos(c.mobile_phone, @__mobilePhone_0) > 0)

i simply want to generate

-- @__mobilePhone_0='42534'
SELECT *
FROM customers AS c
WHERE c.mobile_phone LIKE '%@__mobilePhone_0%'`
Svyatoslav Danyliv
  • 21,911
  • 3
  • 16
  • 32

1 Answers1

0

There is a Like extension method: https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.dbfunctionsextensions.like?view=efcore-7.0

Use it like this:

query = query.Where(x => EF.Functions.Like(x.MobilePhone, $"%{mobilePhone}%"));
Tao Gómez Gil
  • 2,228
  • 20
  • 36