Cha*_*eus 4 c# sql ado.net spatial-query
我想重构这个方法(来自Rob Conery的Massive.cs):
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);
}
Run Code Online (Sandbox Code Playgroud)
可能添加一个Geography类型的检查将解决我的问题与ExecuteNonQuery和空间数据类型,但我会检查什么类型?
if (item.GetType() == typeof(//WhatType?//)) {}
| 归档时间: |
|
| 查看次数: |
5735 次 |
| 最近记录: |