/ Published in: C#
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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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); } } }