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?//)) {}
SqlGeography is what you're looking for, I believe.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With