String.FirstOrDefault() LINQ queries now supported in Entity Framework Core 5.0

Entity Framework Core 5.0 now supports the translation of String.FirstOrDefault() LINQ queries.

In EF Core 3.1 the following would fail…

FirstOrDefault now supported in Entity Framework

with an error message similar to below but in 5.0 it translates into a query using substring().

String.FirstOrDefault translation error
Note… a potential performance gotcha with EF Core < 3.0 was that any queries it couldn’t translate were evaluated on the client (.NET side). This often resulted in performance problems in production as huge numbers of records could be returned to the client AND THEN filtered. Since version 3.0 Entity Framework Core will throw an exception if anything can’t be translated but watch out for this in earlier versions.

Leave a Reply

Your email address will not be published. Required fields are marked *