Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 = 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?//)) {}

like image 322
Chaddeus Avatar asked Dec 27 '22 22:12

Chaddeus


1 Answers

SqlGeography is what you're looking for, I believe.

like image 125
Dan Gartner Avatar answered Jan 22 '23 12:01

Dan Gartner