EF Core Like Operations and Global Filters

Learn about pattern matching with LIKE, and searching for patterns within a database table.

Pattern matching with Like

EF Core supports common SQL statements, including Like for pattern matching:

Step 1: In Program.Queries.cs, add a method named QueryingWithLike, as shown in the following code and note:

  • We have enabled logging.

  • We prompt the user to enter part of a product name and then use the EF.Functions.Like method to search anywhere in the ProductName property.

  • For each matching product, we output its name, stock, and if it is discontinued:

Get hands-on with 1400+ tech skills courses.