Reputation: 6514
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!
Upvotes: 2
Views: 4148
Reputation: 364369
As I understand your current entity doesn't map Latitude
and Longitude
. 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 Geography
data type you must also provide view which will break it into separate Latitude
and Longitude
columns. Your entity must have Longitude
and Latitude
as properties and must be mapped to the view. Your procedures must accept mapped Latitude
and Longitude
as parameters.
Next major version of EF should support Geography
directly.
Upvotes: 3
Reputation: 1542
Assuming that you have used ADO.NET Entity Data Model to map between EF and your database the easiest way to map to a SP is to used the wizard in the Model Browser.
This will create a new function that you can use. It will handle communicating with your SP including the parameters while you can use it just like an ordinary function.
Upvotes: 2