private static string GetParametersToken(EntityCommand entityCommand) { if (entityCommand.Parameters == null || entityCommand.Parameters.Count == 0) { return("@@0"); } Dictionary <string, TypeUsage> parameterTypeUsage = entityCommand.GetParameterTypeUsage(); if (1 == parameterTypeUsage.Count) { return("@@1:" + entityCommand.Parameters[0].ParameterName + ":" + EntityClientCacheKey.GetTypeUsageToken(parameterTypeUsage[entityCommand.Parameters[0].ParameterName])); } StringBuilder stringBuilder = new StringBuilder(entityCommand.Parameters.Count * 20); stringBuilder.Append("@@"); stringBuilder.Append(entityCommand.Parameters.Count); stringBuilder.Append(":"); string str = ""; foreach (KeyValuePair <string, TypeUsage> keyValuePair in parameterTypeUsage) { stringBuilder.Append(str); stringBuilder.Append(keyValuePair.Key); stringBuilder.Append(":"); stringBuilder.Append(EntityClientCacheKey.GetTypeUsageToken(keyValuePair.Value)); str = ";"; } return(stringBuilder.ToString()); }
/// <summary> /// Returns a string representation of the parameter list /// </summary> /// <param name="entityCommand"> </param> /// <returns> </returns> private static string GetParametersToken(EntityCommand entityCommand) { if (null == entityCommand.Parameters || 0 == entityCommand.Parameters.Count) { // // means no parameters // return("@@0"); } // Ensure that parameter DbTypes are valid and there are no duplicate names var paramTypeUsage = entityCommand.GetParameterTypeUsage(); Debug.Assert( paramTypeUsage.Count == entityCommand.Parameters.Count, "entityParameter collection and query parameter collection must have the same number of entries"); if (1 == paramTypeUsage.Count) { // if its one parameter only, there is no need to use stringbuilder return("@@1:" + entityCommand.Parameters[0].ParameterName + ":" + GetTypeUsageToken(paramTypeUsage[entityCommand.Parameters[0].ParameterName])); } else { var sb = new StringBuilder(entityCommand.Parameters.Count * EstimatedParameterStringSize); Debug.Assert( paramTypeUsage.Count == entityCommand.Parameters.Count, "entityParameter collection and query parameter collection must have the same number of entries"); sb.Append("@@"); sb.Append(entityCommand.Parameters.Count); sb.Append(":"); var separator = ""; foreach (var param in paramTypeUsage) { sb.Append(separator); sb.Append(param.Key); sb.Append(":"); sb.Append(GetTypeUsageToken(param.Value)); separator = ";"; } return(sb.ToString()); } }