score:32
Accepted answer
you should be able to use a scalar sql function in your where
criterias with codefirststorefunctions
assuming you want to map sql function [dbo].[latlongdistancecalc], and according to the test suite:
public class mydatacontext: dbcontext
{
protected override void onmodelcreating(dbmodelbuilder modelbuilder)
{
//...
modelbuilder.conventions.add(new functionsconvention("dbo", this.gettype()));
}
// "codefirstdatabaseschema" is a convention mandatory schema name
// "latlongdistancecalc" is the name of your function
[dbfunction("codefirstdatabaseschema", "latlongdistancecalc")]
public static int latlongdistancecalc(int fromlat, int fromlong,
int tolat, int tolong)
{
// no need to provide an implementation
throw new notsupportedexception();
}
}
usage would then be:
context.locations
.where(e => mydatacontext.latlongdistancecalc(e.lat, e.long, lat, long) >= 10)
Source: stackoverflow.com
Related Query
- Entity Framework 6 Code First Custom Functions
- LINQ - Entity framework code first - Grouped results to custom class
- Entity Framework Code First without app.config
- Entity Framework Code First using context in Controller
- many to many mapping in entity framework code first
- How to Create a Run-Time Computed (NotMapped) Value in Entity Framework Code First
- updating data in many-to-many relationship in entity framework in code first existing database
- Entity Framework Code First String Comparison with Oracle Db
- SQL subquery result in LINQ and Entity Framework Code First
- most efficient Entity Framework Code First method of flattening / projecting parent entity with specific child
- Entity Framework Code First - Get blog posts which have certain tags
- How to Query Icollections of Entity Framework Code First Data
- Entity Framework code first - Many to Many - Include conditional
- Entity Framework Code First ToList method timing out on SQL Azure
- How to make a property unique in Entity Framework Code First
- Entity Framework Code First override onModelCreating() for TPT Inheritance Screwing Up Identity User and Role Models
- How to loop through a child list of objects in Entity Framework 4.1 code first
- how to select data by linq in many-to-many relationship in First code Entity framework 5
- Why Entity Framework Code First one to many Doesn't work properly
- map one to one with multiple primary key columns entity framework code first
- Does Linq in Entity Framework code first use SQL or does it get the whole table first?
- Fixing Loop Reference in Entity Framework Code First when Serializing to Json
- IQueryable two tables from Code First Entity Framework
- Entity Framework Code First Select Item Based on Relationship
- Getting InvalidCastException when trying to implement sorting in Entity Framework Code First using Linq
- c# WPF bind combobox to TPH in Entity Framework code first using LINQ
- Proper Linq Query for objects with many to many relation ship generated with code first entity framework
- Code First Entity Framework Linq Statement Returning Missing Records
- Entity Framework Code First Dynamic Queries
- Entity Framework Code First - Maintain a Long connection to Database
More Query from same tag
- Where is the "Fold" LINQ Extension Method?
- Select Single Parent with Multiple Children into Custom Entity
- Extreme Slowness with Linq on mass update
- Left Join LINQ and using Bitwise Comparisons
- LINQ: Customize the count method
- Return function for list of id's
- The specified type member 'Product' is not supported in LINQ to Entities
- Expression tree from IronPython
- ComboBox DataBinding DisplayMember and LINQ queries
- LINQ Pivot to Excel File
- Add mutliple Lists to one list
- Incorporate if clause into linq
- Linq to SQL sort by fields in 2 entities (parent-child)
- cast property inside linq where clause
- Update one collection based on another collection value
- Compare items in two lists and replace foreach loop with LINQ
- Great difference in Entity Framework query speed. But why?
- How to check for nulls in a deep lambda expression?
- Implementing Advanced Filter Page
- Problem auto-assigning sequential value for new items
- Convert to dot notation
- System.Reflection.MissingRuntimeArtifactException - in release mode
- How to check null reference before it throws an exception?
- Match Characters in LINQ Query
- Left Trim in Linq
- Linq selecting from GroupBy
- c# changing this line so it outputs the string as a variable
- using linq to find consecutive elements in an array
- Grouping data with dynamic keys with Linq
- Stop Linq2SQL using Named Pipes?