I've created the model using System.Data.Entity.Spatial;
public class Store
{
public int Id { get; private set; }
public string Name { get; set; }
public string Address { get; set; }
public DbGeography Location { get; set; }
}
Inserting to DB
using (SqlConnection conn = SqlHelper.GetOpenConnection())
{
const string sql = "INSERT INTO Stores(Name, Address, Location) " +
"VALUES (@Name, @Address, @Location)";
return conn.Execute(sql, store);
}
i get the exception type System.Data.Entity.Spatial.DbGeography cannot be used as a parameter value
I've tried searching for ways to insert, this is the best i can find, but it's trying to insert only 1 parameter, what should i do in order to insert an object that have a dbgeography member?
Update #1
I've gave up trying to hack around or extend stuff, as i'm very new to dapper and time is not currently on my side. I went back to basic doing this, as i'm not required to do geography data type insertion very frequently
using (SqlConnection conn = SqlHelper.GetOpenConnection())
{
var sql = "INSERT INTO Stores (Name, Address, IsActive, Location, TenantId) " +
"VALUES('@Name', '@Address', @IsActive, geography::Point(@Lat,@Lng, 4326), @TenantId);";
return conn.Execute(sql, new
{
Name = store.Name,
Address = store.Address,
IsActive = store.IsActive,
Lat = store.Location.Latitude.Value,
Lng = store.Location.Longitude.Value,
TenantId = store.TenantId
});
}