Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework Core Postgres ILike function

context.Company.Where(i => EF.Functions.ILike(i.Name, "xxx%")).FirstOrDefault()

I just need to use ILike in EF Core. But this function is Postgres specific. If some day the database change to Sql Server. All the code like this need to be updated.

Any ways to avoid this issue?

like image 606
amingo Avatar asked Sep 01 '25 10:09

amingo


1 Answers

This seems to be database agnostic:

context.Counties.Where(x => x.Name.ToLower().Contains(keyword.ToLower())).ToList();

From: https://stackoverflow.com/a/56043524

like image 63
DharmaTurtle Avatar answered Sep 03 '25 00:09

DharmaTurtle