我生成函数
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);
SQL服务器上的看起来像这样:
CREATE PROCEDURE [dbo].[sp_FindLastGeofenceEnterOrExit]
@assetId bigint,
@geofence geography,
@startDate datetime,
@isEnter bit
AS
但是当我尝试调用该函数时VS会抛出异常:
无法弄清楚EF是否支持它。我使用EF 6.0.0.0
答案 0 :(得分:1)
EF6肯定支持存储过程中的地理类型(EF5也是如此)。虽然我之前只使用过数据库,但我从EDMX文件中提取了这个(略有修改和简化)。希望它有所帮助。
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);
}