I'm working on a new website that's using entity framework.

Using code from another site, that was linq to sql, I have a database function to calculate distance from one set of latitude and longitude to another set. And the function returns a decimal with the distance.

I've added to my identitymodel.cs in the ApplicationDbContext class:

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    public ApplicationDbContext()
        : base("DefaultConnection", throwIfV1Schema: false)

    public static ApplicationDbContext Create()
        return new ApplicationDbContext();
 public ObjectResult<int> getDistance(string lat1, string lon1, string lat2, string lon2)
        var params1 = new[] {
            new ObjectParameter("lat1", lat1),
            new ObjectParameter("lon1", lon1),
            new ObjectParameter("lat2", lat2),
            new ObjectParameter("lon2", lon2)

        return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<int>("LatLonRadiusDistance", params1);

And this is my query:

var datap = (from p in db.table
                     where db.LatLonRadiusDistance(data.lat, data.lon, p.platitude, p.plongitude) <= 10
                     select new latlon
                         lat = p.property_lat,
                         lon = p.property_lon,
                         address = p.property_address,
                         id = p.property_id,
                         count = ecount

However now I'm getting an error:

The FunctionImport 'LatLonRadiusDistanceVarchar' could not be found in the container 'ApplicationDbContext'.

What am I doing wrong?

Related posts

Recent Viewed