Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of SqlFunctions in EF Core

What is the equivalent of SqlFunctions in Entity Framework (EF) Core 2.0?

I am trying to convert this to EF Core

private static readonly MethodInfo StringConvertMethodDouble = typeof(SqlFunctions).GetMethod("StringConvert", new Type[] { typeof(double?) });

Edit #1: I should specify that I am generating a dynamic linq query with expression tree to query the database

Thanks

like image 818
Zulander Avatar asked Feb 21 '18 02:02

Zulander


People also ask

Is EF core faster than EF6?

EF Core 6.0 itself is 31% faster executing queries. Heap allocations have been reduced by 43%.

How do I use functions in EF core?

EF Core allows for using user-defined SQL functions in queries. To do that, the functions need to be mapped to a CLR method during model configuration. When translating the LINQ query to SQL, the user-defined function is called instead of the CLR function it has been mapped to.

Does EF core support EDMX?

EF Core does not support the EDMX file format for models. The best option to port these models, is to generate a new code-based model from the database for your application.


Video Answer


1 Answers

EF Core surfaces functions via EF.Functions, however in 2.0 only Like is available:

ctx.TestEntities.Any(entity => EF.Functions.Like(entity.Name, "%foo%"))
like image 74
Martin Ullrich Avatar answered Sep 29 '22 13:09

Martin Ullrich