I'm using ASP.NET Core 7, and I am trying to read in spatial data from a SQL Server. I'm trying to execute a query and map it to a strongly typed list:
public class MyDataSchema {
public int id {get; set;}
public SqlGeography spatialData {get; set;}
}
using (SqlConnection con = new SqlConnection('ConnectionStringHere'){
var data = con.Query<MyDataSchema>("Select * from <Table_Name>").ToList();
}
This code works for all data except for when the spatialData column is included. In that case it throws the following error:
An exception of type 'System.Data.DataException' occurred in Dapper.dll but was not handled in user code: 'Error parsing column 2 (spatialData=1234 - Double)' Microsoft.SqlServer.Server.InvalidUdtException : 'Microsoft.SqlServer.Types.SqlGeography' is an invalid user defined type, reason: no UDT attribute.
I believe the SQL Server update to 2012 broke it link. I cannot change the version of the SQL Server, and I wasn't sure how to implement the example using Dapper. Has anyone had experience with this?
I tried implementing a Dapper SQLMapper Type handler for the SQLGeography, but the error still occurred despite adding the type handler via SqlMapper.AddTypeHandler(new SpatialDataHandler());
.