我正在阅读Microsoft.ApplicationBlocks.Data的代码(代码在这里)
但我注意到一些奇怪的事情:
在其中一个函数(executeNonQuery)中,他尝试从缓存中读取 Sp 的参数,如果不存在,他将它们放入缓存(不是 asp.net 缓存 - 而是一个内部 HashSet)
public static int ExecuteNonQuery(string connectionString, string spName, params SqlParameter[] parameterValues)
{
if (connectionString == null || connectionString.Length == 0) throw new ArgumentNullException("connectionString");
if (spName == null || spName.Length == 0) throw new ArgumentNullException("spName");
// If we receive parameter values, we need to figure out where they go
if ((parameterValues != null) && (parameterValues.Length > 0))
{
// Pull the parameters for this stored procedure from the parameter cache (or discover them & populate the cache)
//------------------------------------
SqlParameter[] commandParameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, spName);
//------------------------------------
// Assign the provided values to these parameters based on parameter order
AssignParameterValues(commandParameters, parameterValues);
// Call the overload that takes an array of SqlParameters
return ExecuteNonQuery(connectionString, CommandType.StoredProcedure, spName, commandParameters);
}
else
{
// Otherwise we can just call the SP without params
return ExecuteNonQuery(connectionString, CommandType.StoredProcedure, spName);
}
}
请看隔离线。
他们为什么这样做?如果我在 Cache 中有参数,它对我有什么帮助?无论如何,我都会从我的 dal 发送参数……(而且我必须将我的参数发送给 SP)……
我错过了什么?