Entity framework EF.Functions.Like vs string.Contains

后端 未结 2 828
小蘑菇
小蘑菇 2020-12-02 22:22

I was reading the announcement of entity framework core 2.0 https://blogs.msdn.microsoft.com/dotnet/2017/08/14/announcing-entity-framework-core-2-0/

It says that the

2条回答
  •  天涯浪人
    2020-12-02 22:30

    Like query supports wildcard characters and hence very useful compared to the string extension methods in some scenarios.

    For ex: If we were to search all the 4 lettered names with 'ri' as the middle characters we could do EF.Functions.Like(c.Name, "_ri_");

    or to get all the customers from cities which start with vowels:

    var customers = from c in context.Customers 
                       where EF.Functions.Like(c.City, "[aeiou]%")
                       select c;
    

    (Please read @Tseng's answer on how they are translated differently into SQL queries)

提交回复
热议问题