Browse Source

Code optimization

pull/12/MERGE
sunkaixuan 6 years ago
parent
commit
718e630ea5
  1. 5
      Src/Asp.Net/SqlSugar/SqlSugarClient.cs
  2. 9
      Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs

5
Src/Asp.Net/SqlSugar/SqlSugarClient.cs

@ -840,10 +840,7 @@ namespace SqlSugar
var newName = itemParameter.ParameterName + "_q_" + index; var newName = itemParameter.ParameterName + "_q_" + index;
SugarParameter parameter = new SugarParameter(newName, itemParameter.Value); SugarParameter parameter = new SugarParameter(newName, itemParameter.Value);
parameter.DbType = itemParameter.DbType; parameter.DbType = itemParameter.DbType;
itemSql = Regex.Replace(itemSql,string.Format(@"{0} ","\\"+itemParameter.ParameterName), newName+" ",RegexOptions.IgnoreCase); itemSql = UtilMethods.ReplaceSqlParameter(itemSql, itemParameter, newName);
itemSql = Regex.Replace(itemSql, string.Format(@"{0}\)", "\\" + itemParameter.ParameterName), newName+")", RegexOptions.IgnoreCase);
itemSql = Regex.Replace(itemSql, string.Format(@"{0}\,", "\\" + itemParameter.ParameterName), newName+",", RegexOptions.IgnoreCase);
itemSql = Regex.Replace(itemSql, string.Format(@"{0}$", "\\" + itemParameter.ParameterName), newName, RegexOptions.IgnoreCase);
addParameters.Add(parameter); addParameters.Add(parameter);
} }
parsmeters.AddRange(addParameters); parsmeters.AddRange(addParameters);

9
Src/Asp.Net/SqlSugar/Utilities/UtilMethods.cs

@ -17,7 +17,14 @@ namespace SqlSugar
Type type = Nullable.GetUnderlyingType(oldType); Type type = Nullable.GetUnderlyingType(oldType);
return type == null ? oldType : type; return type == null ? oldType : type;
} }
public static string ReplaceSqlParameter(string itemSql, SugarParameter itemParameter, string newName)
{
itemSql = Regex.Replace(itemSql, string.Format(@"{0} ", "\\" + itemParameter.ParameterName), newName + " ", RegexOptions.IgnoreCase);
itemSql = Regex.Replace(itemSql, string.Format(@"{0}\)", "\\" + itemParameter.ParameterName), newName + ")", RegexOptions.IgnoreCase);
itemSql = Regex.Replace(itemSql, string.Format(@"{0}\,", "\\" + itemParameter.ParameterName), newName + ",", RegexOptions.IgnoreCase);
itemSql = Regex.Replace(itemSql, string.Format(@"{0}$", "\\" + itemParameter.ParameterName), newName, RegexOptions.IgnoreCase);
return itemSql;
}
internal static Type GetRootBaseType(Type entityType) internal static Type GetRootBaseType(Type entityType)
{ {
var baseType = entityType.BaseType; var baseType = entityType.BaseType;

Loading…
Cancel
Save