Question

I generate the function

    if (geofence != null)
    {
        geofenceParameter = new ObjectParameter("geofence", geofence);
    }
    else
    {
        geofenceParameter = new ObjectParameter("geofence", typeof(System.Data.Spatial.DbGeography));
    }

base.ExecuteFunction<AssetData>("FindLastGeofenceEnterOrExit", assetIdParameter, geofenceParameter, startDateParameter, isEnterParameter);

on SQL server it looks like this:

CREATE PROCEDURE [dbo].[sp_FindLastGeofenceEnterOrExit]
@assetId bigint,
@geofence geography,
@startDate datetime,
@isEnter bit
AS

But when i try to call that function VS throws the exception: enter image description here

Can't figure out does EF supports it or not. I use EF 6.0.0.0

Was it helpful?

Solution

EF6 definitely supports geography types in stored procedures (as did EF5). Although I've only worked database first, I pulled this (modified slightly and simplified) from the EDMX file. Hope it helps.

public virtual ObjectResult<MyClass> MyStoredProcedure(System.Data.Spatial.DbGeography location, MergeOption mergeOption)
{
    var locationParameter = location != null ?
        new ObjectParameter("location", location) :
        new ObjectParameter("location", typeof(System.Data.Spatial.DbGeography));

    // EDIT: Neglected to copy this part in during original post
    return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<MyClass>("MyStoredProcedure", mergeOption, locationParameter);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top