score:7
this should work in linq to objects if getdistance()
returns a boolean - it will not work with linq to entities since it will try to map your method to a sql equivalent, which of course there is none.
as a crude workaround you could use asenumerable()
but that would materialize all your types so is not recommended if your table is larger:
mytypes = mytypes.asenumerable()
.where(x => getdistance(x.zip, givenzip) < 10);
another way would be to map zip codes to geographic locations in the database and use those locations directly with the soon to be supported spatial data types - this is probably the best approach in my opinion, but not production-ready. of course if you are restricted to just sql server you could just use a store query directly to use geo-locations - but that would work around ef.
score:0
assuming:
list<mytype> mytypes;
try:
mytypes = mytypes.where(x => getdistance(x.zip, givenzip) < 10).tolist();
score:3
this will throw an error because the runtime tries to convert your expression tree into sql. the function 'getdistance' cannot be converted.
have a look at model defined functions. they allow you to define a custom function in your edmx which you can execute when building queries.
Source: stackoverflow.com
Related Query
- How to call a method in the where clause of a LINQ query on a IQueryable object
- How to call method/function in where clause of a LINQ query as IEnumerable object
- How can I keep the the logic to translate a ViewModel's values to a Where clause to apply to a linq query out of My Controller?
- How to AND predicates in the WHERE clause in a LINQ to RavenDB query
- As I can call a method in the where clause in LINQ 3.5?
- How to query and calculate dates in the where clause of a LINQ statement?
- How to safely use the .substring method in a linq where clause
- LINQ to Object - How to implement WHERE clause `If at least one of the elements is` for sub-group
- Calling a boolean method inside the where clause of a Linq query
- LINQ Query with dynamic where clause based on search criteria that is NOT part of the returned object
- How to execute a linq query for each item in a list , use it in the where clause and return a collection from the result of each query?
- How to call a local method from the linq query
- How do I add a where clause to a field that is not part of the return set for LINQ query
- How to query in linq that the field that should be in the where clause is a concatenation of fields
- How to get linq `ForEach` statement to return data on the method call being made for each list object?
- LINQ Where clause with Contains where the list has complex object
- Call class method inside the Linq Query
- trying to call a method in the where of a linq statment
- When using a LINQ Where clause on a Dictionary, how can I return a dictionary of the same type?
- Where clause not working on LINQ IQueryable query
- how to put conditional WHERE clause within LINQ query
- Linq with where clause in many-to-many EF Code First object
- How can I write the following code more elegantly using LINQ query syntax?
- How to get the where clause from IQueryable defined as interface
- How to call custom method in linq query
- Issue in Linq to object where clause : the condition is bypassed
- Removing the WHERE clause in a Linq query
- How to query by where clause with EF code first
- How can I have a linq query conditionally NOT apply a where clause
- Linq - How to apply a where clause on the maximum element of a list
More Query from same tag
- query problem with linq: Unable to cast object
- C# Not able to use CopyToDataTable() function when grouping fields by LINQ & Datatable
- How to avoid memory overflow when querying large datasets with Entity Framework and LINQ
- Extracting Attribute from the whole XDocument
- How to sort the list order using Linq?
- Should AddRange() return a list
- linq union group by undefined
- htmlagilitypack select nodes return null
- Get combined Expression<TDelegate> from IQueryable
- Transform sequence in Linq while being aware of each Select/SelectMany result
- Is it possible sorting by column position in linq?
- Linq making very inefficient Entity Framework query
- LINQ EF Join query from 2 different data context
- What is the difference between LINQ ToDictionary and ToLookup
- Save/Serialize LINQ query
- Upgraded to .NET Core 3.1 and receiving an error in a LINQ query related to using .FirstOrDefault()
- Understanding Select operation | Azure Cosmos DB Table API
- 'Inject' one expression into another
- How to Transform in to one function using generics or dynamic?
- C# how to modify this method to return only with matching criteria?
- LINQ to Entities query error
- LINQ query for retrieving items that contain any value from a list?
- LINQ and Activator.CreateInstance() creates duplicates
- use Linq to process groups of items in a list
- SUM() in SQL to LINQ
- Linq Projection being cached incorrectly in NHibernate 3.2
- How to Extract SVG children html tag from xml file using linq in C#
- Groupby DateTime for specific intervals
- How can you take only the last result with Linq
- Linq Group By & Sum Query On Multiple Columns