使用匹配类属性上的关联向命令对象添加参数
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用匹配类属性上的关联向命令对象添加参数相关的知识,希望对你有一定的参考价值。
You could eliminate the ListDictionary if you created a simple method to map C# types to DbTypes. Although this method also lets you skip over some object properties my using the ListDictionary to contain a subset of properties. It could also be used to map properties to param names if they needed to differ.
private void AddParameters(Database db, DbCommand comm, PropertyInfo[] properties, ListDictionary parameters, object target) { foreach (PropertyInfo pi in properties) { string paramName = pi.Name; if (parameters.Contains(paramName)) { System.Data.DbType paramType = (System.Data.DbType)parameters[paramName]; object value = pi.GetValue(target, null); db.AddInParameter(comm, paramName, paramType, value); } } }
以上是关于使用匹配类属性上的关联向命令对象添加参数的主要内容,如果未能解决你的问题,请参考以下文章