I’m trying to create an entity in my model that has two properties for specifying it’s latitude and longitude. In Sql Server 2008 R2, I’m using a single column in a table to store this information. The column is of type geography. In order to use the entity against the database, I was hoping to map 3 stored procedures to insert, update, and delete rows from the appropriate table in the database. However, I’m having trouble getting the assembly containing my model to compile without any errors. I’m still pretty new to using EF 4, so I’m not quite sure how to do this correctly. My partial class looks like:
public partial class MyEntity
{
private double latitude;
private double longitude;
public double Latitude { get {return latitude;} set {latitude = value; }
public double Longitude { get {return longitude;} set {longitude = value; }
}
My stored procedures take parameters of Latitude and Longitude (except for the delete stored procedure). However, when I try to compile the project, I get the error:
A mapping function bindings specifies a function
MyNamespace.Store.sp_insertMyEntity but does not map the following
function parameters: Latitude, Longitude.
I must be declaring the properties incorrectly, somehow. Perhaps it’s in my model. Any suggestions will be welcome!
As I understand your current entity doesn’t map
LatitudeandLongitude. That means you can never load them from database and you also cannot save them to database – no way.Your stored procedure cannot expect any parameter which is not supported by EF. If your database table uses
Geographydata type you must also provide view which will break it into separateLatitudeandLongitudecolumns. Your entity must haveLongitudeandLatitudeas properties and must be mapped to the view. Your procedures must accept mappedLatitudeandLongitudeas parameters.Next major version of EF should support
Geographydirectly.