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.

57 lines
2.3 KiB

2 years ago
  1. using System.Collections.Generic;
  2. namespace SqlSugar
  3. {
  4. internal class CacheKeyBuider
  5. {
  6. public static CacheKey GetKey(SqlSugarClient context, QueryBuilder queryBuilder)
  7. {
  8. var result = new CacheKey
  9. {
  10. Database = context.Context.Ado.Connection.Database
  11. };
  12. AddTables(context, queryBuilder, result);
  13. AddIdentificationList(queryBuilder, result);
  14. return result;
  15. }
  16. private static void AddIdentificationList(QueryBuilder queryBuilder, CacheKey result)
  17. {
  18. result.IdentificationList = new List<string>();
  19. result.IdentificationList.Add(queryBuilder.GetTableNameString);
  20. result.IdentificationList.Add(queryBuilder.GetJoinValueString);
  21. result.IdentificationList.Add(queryBuilder.GetOrderByString);
  22. result.IdentificationList.Add(queryBuilder.GetGroupByString);
  23. result.IdentificationList.Add(queryBuilder.GetWhereValueString);
  24. result.IdentificationList.Add(queryBuilder.PartitionByValue);
  25. result.IdentificationList.Add(queryBuilder.Take.ObjToString());
  26. result.IdentificationList.Add(queryBuilder.Skip.ObjToString());
  27. if (queryBuilder.Parameters.HasValue())
  28. {
  29. foreach (var item in queryBuilder.Parameters)
  30. {
  31. result.IdentificationList.Add(item.ParameterName + "_" + item.Value);
  32. }
  33. }
  34. }
  35. private static void AddTables(SqlSugarClient context, QueryBuilder queryBuilder, CacheKey result)
  36. {
  37. result.Tables = new List<string>();
  38. result.Tables.Add(context.EntityMaintenance.GetTableName(queryBuilder.EntityName));
  39. if (queryBuilder.EasyJoinInfos.HasValue())
  40. {
  41. foreach (var item in queryBuilder.EasyJoinInfos)
  42. {
  43. result.Tables.Add(context.EntityMaintenance.GetTableName(item.Value));
  44. }
  45. }
  46. if (queryBuilder.JoinQueryInfos.HasValue())
  47. {
  48. foreach (var item in queryBuilder.JoinQueryInfos)
  49. {
  50. result.Tables.Add(queryBuilder.Builder.GetNoTranslationColumnName(item.TableName));
  51. }
  52. }
  53. }
  54. }
  55. }