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

Viewed 8187

There are Q+A's for Entity Framework LIKE's in the Full .net framework:

How to do SQL Like % in Linq?
Like Operator in Entity Framework?

eg:

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

This doesn't work in EF Core:

The name SqlMethods does not exist in the current context.

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

3 Answers

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

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

Instead of Like function you can use Contains

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

Fluent version:

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