It may sound obvious, but why not use the same data type that has been installed as a UDT in SQL Server - SqlGeography
?
The following works fine against a SQL Server 2012 instance. I'm unable to test against SQL Server 2008 but I'd assume it should work the same:
using System;
using Microsoft.SqlServer.Types;
using System.Data.SqlClient;
using System.Data;
namespace ConsoleApplication4
{
class Program
{
static void Main()
{
var geom1 = SqlGeography.STGeomFromText(
new System.Data.SqlTypes.SqlChars(
"LINESTRING(-122.360 47.656, -122.343 47.656)"), 4326);
var geom2 = SqlGeography.STGeomFromText(
new System.Data.SqlTypes.SqlChars(
"LINESTRING(-100.0 45.0, -1420 49.0)"), 4326);
using(var conn = new SqlConnection(
@"Server=Server;Database=master;Integrated Security=SSPI;"))
{
using (var cmd = new SqlCommand(
"select @parm1.STIntersects(@parm2)", conn))
{
var p1 = cmd.Parameters.Add("@parm1", SqlDbType.Udt);
p1.UdtTypeName = "geography";
p1.Value = geom1;
var p2 = cmd.Parameters.Add("@parm2", SqlDbType.Udt);
p2.UdtTypeName = "geography";
p2.Value = geom2;
conn.Open();
Console.WriteLine(cmd.ExecuteScalar());
}
}
Console.ReadLine();
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…