/// <summary> /// 构造缓存键值。 /// </summary> /// <param name="builder">select命令构造器。</param> /// <param name="tag">标记。</param> /// <param name="type">类型。</param> /// <returns>返回缓存键值。</returns> protected virtual string BuildCacheKey(Symbol.Data.ISelectCommandBuilder builder, string tag, Type type) { return(string.Concat( tag, ":", type.AssemblyQualifiedName, "|", builder.CommandText, "/", Symbol.Serialization.Json.ToString(builder.Parameters, true) )); }
/// <summary> /// 缓存键值操作。 /// </summary> /// <param name="cache">缓存对象。</param> /// <param name="builder">select命令构造器。</param> /// <param name="tag">标记。</param> /// <param name="type">类型。</param> /// <param name="func">缓存求值委托。</param> /// <returns>返回</returns> protected virtual object CacheFunc(IDataBinderObjectCache cache, Symbol.Data.ISelectCommandBuilder builder, string tag, Type type, CacheValueFunc func) { if (cache != null && AllowCache) { object value; string key = BuildCacheKey(builder, tag, type); if (!cache.Get(key, out value)) { value = func(); cache.Set(key, value); } return(value); } else { return(func()); } }
/// <summary> /// select命令构造器预处理(处理$this.xx值引用)。 /// </summary> /// <param name="dataContext">数据上下文对象。</param> /// <param name="dataReader">数据读取对象。</param> /// <param name="entity">当前实体对象。</param> /// <param name="builder">select命令构造器。</param> /// <param name="cache">缓存。</param> protected virtual void PreSelectBuilder(IDataContext dataContext, System.Data.IDataReader dataReader, object entity, Symbol.Data.ISelectCommandBuilder builder, IDataBinderObjectCache cache) { var baseAddCommandParameter = builder.AddCommandParameter; builder.AddCommandParameter = (p) => { string p10 = p as string; if (p10 != null && p10[0] == '$' && p10.Length > 1) { var value = CacheFunc(cache, entity, p10, () => { var func = GetPreSelectBuilderFunc(entity.GetType(), p10); return(func?.Invoke(dataContext, dataReader, entity)); }); //var value = GetPreSelectBuilderFunc(entity.GetType(), p10)?.Invoke(dataContext, dataReader, entity); return(baseAddCommandParameter(value)); } return(baseAddCommandParameter(p)); }; }