I am developing ASP.NET MVC application and use Mysql with entity framework in it. But I'm having trouble with executing Linq query like this:
var place= dbContext.Places.FirstOrDefault(x => Math.Sqrt(x.Lat) > 0);
I also tried using SqlFunctions:
var place= dbContext.Places.FirstOrDefault(x => SqlFunctions.SquareRoot(x.Lat) > 0);
But either way I'm getting 'System.NotSupportedException':
Additional information: The specified method 'System.Nullable1[System.Double] SquareRoot(System.Nullable
1[System.Decimal])' on the type 'System.Data.Entity.SqlServer.SqlFunctions' cannot be translated into a LINQ to Entities store expression.
Is there any way to use Square root function so that it could be translated into a LINQ to Entities expression?
Entity Framework doesn't support Sqrt function:
Math Canonical Functions - list of supported functions.
So you can use Math.Pow insted:
var place= dbContext.Places.FirstOrDefault(x => Math.Pow(x.Lat,0.5) > 0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With