简体   繁体   中英

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

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?

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") 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM