private static K ExecuteStoredProcedure<K>(string connectionString, string storedProcedure, SqlParameter[] parameters, Func<I, K> readFunction)
示例用法如下所示:
return ExecuteStoredProcedure<SqlDataReader, Dictionary<string, string>>(
connectionString,
"uspSearchStatisticsSelectByTokenPerDayGroupByDate",
parameters,
(reader) =>
{
reader.Read();
int readCount = reader.FieldCount;
Dictionary<string, string> results = new Dictionary<string, string>();
results.Add("FailedRequests", Convert.ToString(reader[5]));
results.Add("TotalRequests", Convert.ToString(reader[4]));
results.Add("AverageResponseTime", Convert.ToString(reader[3]));
return results;
}
);
编译器返回
错误 520 找不到类型或命名空间名称“I”(您是否缺少 using 指令或程序集引用?)
但我认为它应该可以参考?
更新:我试图寻找一些过于通用的东西并且并不真正需要它。
我已经去了以下......
private static K ExecuteStoredProcedure<K>(string connectionString, string storedProcedure, SqlParameter[] parameters, Func<SqlDataReader, K> readFunction)