SQL Server How to do a LIKE in Entity Framework CORE (not full .net)

5hcedyr0  于 2023-08-02  发布在  .NET
关注(0)|答案(3)|浏览(143)

In the Full .Net EF LIKE's used to be SqlMethods.Like , eg:

from c in dc.Organization
where SqlMethods.Like(c.Boss, "%Jeremy%")

This doesn't work in EF Core and I get this error:

The name SqlMethods does not exist in the current context.

So how do you do a LIKE using Entity Framework CORE?

cbeh67ev

cbeh67ev1#

The LIKE function has moved under EF.Functions in Core:

from c in dc.Organization
where EF.Functions.Like(c.Boss, "%Jeremy%")
dw1jzc5e

dw1jzc5e2#

Instead of Like function you can use Contains

from c in dc.Organization
where c.Boss.Contains("Jeremy")
mu0hgdu0

mu0hgdu03#

Fluent version:

dc.Organization.Where(o => EF.Functions.Like(o.Boss, "%Jeremy%"));

相关问题