What type of ADO is the spatial geography type from SQL Server 2008?

I am looking for a refactoring of this method (from Massive.cs from Rob Conieri ):

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); } 

Adding a geography type check is likely to fix my problem with ExecuteNonQuery types and spatial data, but what type should I check?

if (item.GetType() == typeof(//WhatType?//)) {}

+4
source share
2 answers

SqlGeography is what you are looking for, I believe.

+7
source

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; } 
+3
source

Source: https://habr.com/ru/post/1348006/


All Articles