What ADO type is the Geography spatial type from SQL Server 2008?
I am looking to refactor this method (from Massive.cs by Rob Conery):
public static void AddParam(this DbCommand cmd, object item) {
var p = cmd.CreateParameter();
p.ParameterName = string.Format("@{0}", cmd.Parameters.Count);
if (item == null) {
p.Value = DBNull.Value;
} else {
if (item.GetType() == typeof(Guid)) {
p.Value = item.ToString();
p.DbType = DbType.String;
p.Size =开发者_如何学C 4000;
} else if (item.GetType() == typeof(ExpandoObject)) {
var d = (IDictionary<string, object>)item;
p.Value = d.Values.FirstOrDefault();
} else {
p.Value = item;
}
//from DataChomp
if (item.GetType() == typeof(string))
p.Size = 4000;
}
cmd.Parameters.Add(p);
}
Likely adding a check for Geography type will fix my issue with ExecuteNonQuery and spatial data types, but what type would I check for?
if (item.GetType() == typeof(//WhatType?//)) {}
SqlGeography is what you're looking for, I believe.
How about this?
if (item.GetType() == typeof(Microsoft.SqlServer.Types.SqlGeography))
{
SqlParameter p = new SqlParameter();
p.SqlDbType = System.Data.SqlDbType.Udt;
p.UdtTypeName = "geography";
p.Value = value;
}
精彩评论