You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
968 B

2 years ago
  1. using System.Linq;
  2. namespace SqlSugar
  3. {
  4. public static class DbExtensions
  5. {
  6. public static string ToJoinSqlInVals<T>(this T[] array)
  7. {
  8. if (array == null || array.Length == 0)
  9. {
  10. return ToSqlValue(string.Empty);
  11. }
  12. else
  13. {
  14. return string.Join(",", array.Where(c => c != null).Select(it => (it + "").ToSqlValue()));
  15. }
  16. }
  17. public static string ToSqlValue(this string value)
  18. {
  19. return string.Format("'{0}'", value.ToSqlFilter());
  20. }
  21. /// <summary>
  22. ///Sql Filter
  23. /// </summary>
  24. /// <param name="value"></param>
  25. /// <returns></returns>
  26. public static string ToSqlFilter(this string value)
  27. {
  28. if (!value.IsNullOrEmpty())
  29. {
  30. value = value.Replace("'", "''");
  31. }
  32. return value;
  33. }
  34. }
  35. }