using System.Collections.Generic; namespace SqlSugar { internal class CacheKeyBuider { public static CacheKey GetKey(SqlSugarClient context, QueryBuilder queryBuilder) { var result = new CacheKey { Database = context.Context.Ado.Connection.Database }; AddTables(context, queryBuilder, result); AddIdentificationList(queryBuilder, result); return result; } private static void AddIdentificationList(QueryBuilder queryBuilder, CacheKey result) { result.IdentificationList = new List(); result.IdentificationList.Add(queryBuilder.GetTableNameString); result.IdentificationList.Add(queryBuilder.GetJoinValueString); result.IdentificationList.Add(queryBuilder.GetOrderByString); result.IdentificationList.Add(queryBuilder.GetGroupByString); result.IdentificationList.Add(queryBuilder.GetWhereValueString); result.IdentificationList.Add(queryBuilder.PartitionByValue); result.IdentificationList.Add(queryBuilder.Take.ObjToString()); result.IdentificationList.Add(queryBuilder.Skip.ObjToString()); if (queryBuilder.Parameters.HasValue()) { foreach (var item in queryBuilder.Parameters) { result.IdentificationList.Add(item.ParameterName + "_" + item.Value); } } } private static void AddTables(SqlSugarClient context, QueryBuilder queryBuilder, CacheKey result) { result.Tables = new List(); result.Tables.Add(context.EntityMaintenance.GetTableName(queryBuilder.EntityName)); if (queryBuilder.EasyJoinInfos.HasValue()) { foreach (var item in queryBuilder.EasyJoinInfos) { result.Tables.Add(context.EntityMaintenance.GetTableName(item.Value)); } } if (queryBuilder.JoinQueryInfos.HasValue()) { foreach (var item in queryBuilder.JoinQueryInfos) { result.Tables.Add(queryBuilder.Builder.GetNoTranslationColumnName(item.TableName)); } } } } }