Try SquareRoot function defined in
var objects = from n in context.Products.Where(p => p.r == r) let a = SqlFunctions.SquareRoot((double)n.Latitude) where a < 5 orderby a select n; return objects.Take(100).ToList();
var objects = from n in context.Products.Where(p => p.r == r) let a = Math.Pow((double)n.Latitude, 0.5) where a < 5 orderby a select n;
If you start of learning LINQ with LINQ-to-objects, you'll run into this a lot once you start using LINQ-to-Entities.
You can do pretty much anything that will compile in LINQ-to-objects, because LINQ-to-objects translates into code when compiled.
LINQ-to-Entities (and LINQ-to-SQL) translates into expression trees. So, only the syntax that that specific LINQ provider allowed for is valid. In my first "for real" LINQ-to-Entities expression, which compiled just fine, I ran into this error about 5 times, as one by one I removed code that wasn't handled by LINQ-to-Entities.
So when you see this, it's normal and common. You need to find another way each time.
You could avoid the problem with a logical equivalent:
var objects = from n in context.Products.Where(p => p.r == r) where (double)n.Latitude < 25 orderby a select n; return objects.Take(100).ToList();
You could also pull all the data to the client and then run your code using LINQ-to-objects:
var objects = from n in context.Products.Where(p => p.r == r).ToList() let a = Math.Sqrt((double)n.Latitude) where a < 5 orderby a select n; return objects.Take(100).ToList();
Finally, you should be able to do this math on the server. Check out the System.Data.Objects.SqlClient.SqlFunctions SqlFunctions Class. These functions will translate into the expression. This in particular looks like it might be the ticket.
- LINQ Source Code Available
- Linq to EF - Unsupported Functions
- creating Linq to sqlite dbml from DbLinq source code
- How can I code numerous MIN functions into one LINQ to DataSet query
- source code for LINQ 101 samples
- c# Linq or code to extract groups from a single list of source data
- Convert string to int in one line of code using LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Does the order of LINQ functions matter?
- Linq code to select one item
- How are people unit testing code that uses Linq to SQL
- Entity Framework 6 Code First Custom Functions
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- Syntax to execute code block inside Linq query?
- Use a Inline Table-Valued Functions with Linq and Entity Framework Core
- Simple sql to Linq query with group by and aggregate functions
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- LINQ aggregate functions on bytes, shorts, and unsigned values
- Best open source LINQ provider
- Linq functions give strange compile error when ambiguous use of IEnumerable - possible workarounds?
- Is there a good source that gives an overview of linq optimizations?
- Does this LINQ code perform multiple lookups on the original data?
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- LINQ WHERE method alters source collection
- Linq error - "NotSupportedException: Unsupported overload used for query operator 'Select'"
- Is there a way to inline external functions into an EF Linq query?
- Where can I view LINQ source code?
- Object functions fail within LINQ to Entities Expressions
- Suggestions for designing complex LINQ code
- Is there any way to create a LINQ query as a variable without having the data source (yet)?
- Exclude LINQ results from one query in another LINQ query
- Search XML file using Linq for ID and return name
- LINQ TO XML retrieving Child Element Value
- Inputting Customer.customerID into Advert.cutomerID using LinQ to Sql in MVC3 Razor
- Exception: when trying to use Enumerable.Any Method with Mobile Services query
- Return max repeated item in list
- C# LINQ GroupBy NULL Values
- TakeWhile, but get the element that stopped it also
- Lambda Expression with self reference - what is it doing?
- Dictonary.Keys.Any output
- Foreach substitute in Linq
- How to apply sql join in Linq Entity Framework Core
- How to use LINQ to filter property of child collection using (.Any())
- Can I access the NHibernate ISession instance from IQueryable?
- Foreach look for the first value in the entire list of records. cannot be applied to operator of type method group and bool
- Dynamic LINQ Query not working properly with Taxonomy field
- How would I convert only a subset of column values from a DataRow into a string array using LINQ?
- Convert loop logic to LINQ
- Linq OrderByDescending with inline comparer function
- Convert string to enum in Linq to SQL