private DbCommand CreateCommand(dynamic parameter = null) { return(CreateCommandByParam(command => { if (parameter != null) { var converter = _PC.GetConverter(parameter.GetType()); List <DbParameter> paramList = converter.Item1(parameter); SetSpecialParameters(paramList); command.Parameters.AddRange(paramList.ToArray()); IGrouping <string, DbParameter>[] paramLists = converter.Item2(parameter); if (paramLists.Length == 0) { return; } SetInParams(command, paramLists); } })); }
public void TestParamConvert() { var dc = new DbTypeConverter(); var type = typeof(Student); var ps = TypeExtensions.GetProperties(type, BindingFlags.Instance | BindingFlags.Public) .Where(i => i.CanRead).ToList(); foreach (var item in _Students) { var ds = _Converter.GetConverter(type).Item1(item); Assert.Equal(ps.Count, ds.Count); for (int i = 0; i < ps.Count; i++) { Assert.Equal(dc.Convert(ps[i].PropertyType), ds[i].DbType); Assert.Equal(ParameterDirection.Input, ds[i].Direction); Assert.True(ds[i].IsNullable); Assert.Equal("@" + ps[i].Name, ds[i].ParameterName); var value = ps[i].GetMethod.Invoke(item, new object[0]) ?? DBNull.Value; Assert.Equal(value, ds[i].Value); } } }