score:14
Try SquareRoot function defined in SqlFunctions
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();
score:1
Please try
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;
score:5
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.
Source: stackoverflow.com
Related Query
- 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)?
More Query from same tag
- Searching each property value of an IQueryable collection of T against the value of a search query. How do I test for NOT NULL and CONTAINS together?
- More than 2 tables JOIN in LINQ, scope issue
- Select data from anonymous collection
- C# List Group And Subgroup to TreeView
- replacing value only from an Xelement using linq
- LINQ query to select all that don't match
- Insert fk at the same time as attributes are added
- LINQ Count ocurrences
- Casting generic type in linq query
- null vs default(decimal?) set to null - giving different results
- Going from IQueryable<String> to String
- Comparing Two models shared data types
- Select single random item from list of items
- Convert or display string to currency
- Using dictionary keys as field name in LINQ
- How to use join with multiple conditions in linq-to-Nhibernate
- Anonymous Type from LINQ but I need Array
- Is it possible to use Full Text Search (FTS) with LINQ?
- How to do Python's zip in C#?
- null reference exception on using DefaultIfEmpty()
- Group By Linq resultset
- How to implement "where" clause in linq
- how do I change this sql query [Select MAX(id)] to linq
- Different approach of making linq query is giving different results
- Initialize a List<int> with LINQ query
- Linq cannot find inserted record before submitchanges
- Ignore time portion of DateTime in linq query
- Group by Question in Linq
- ASP.NET Web API return queryable DTOs?
- for in for optimization