EF Core 2.0 improvements – LIKE Operator, Query filters

By | November 17, 2017

Entity Framework (EF) Core 2.0 comes with some cool nifty features. Improved LINQ translation to optimized SQL queries,  long pending feature request for LIKE LINQ operator is finally fulfilled. Other interesting feature is setting up Global Query filters which essentially allow you to set up global WHERE function at DbContext level and C# string interpolation support in Raw SQL extension.

LIKE Operator:

I’m sure any .Net dev can relate to this piece of code. Self-explanatory. No more Contains or StartsWith extensions. This code generates clean SQL query contains LIKE function

Global Query filters:

Query filters as shown below can make our life easy helping avoid repetitive code by having global filters set directly on the context.

String Interpolation support in FromSql method:

I’m not a big fan of implementing raw SQL queries in EF context. Rather, I recommend Dapper for those raw power needs. Unless, you’ve a compelling case or ad hoc  need, use them sparingly.

Inspired by following .Net blog post . For further reading, check them out!!

https://blogs.msdn.microsoft.com/dotnet/2017/08/14/announcing-entity-framework-core-2-0/