public virtual IEnumerable <Stream> LoadData(object key, IEnumerable <string> tags = null, IEnumerable <Criteria> criterias = null, DateTime?fromDateTime = null, DateTime?tillDateTime = null, int skip = 0, int take = 0) { if (Options.EnableLogging) { Log.Debug( $"{TableName} load: key={key}, tags={tags?.Join("||")}, criterias={criterias?.Select(c => c.Name + ":" + c.Value).Join("||")}"); } using (var conn = CreateConnection()) { var sql = new StringBuilder($"{SqlBuilder.BuildUseDatabase(Options.DatabaseName)} {SqlBuilder.BuildDataSelectByKey(TableName)}"); foreach (var t in tags.NullToEmpty()) { sql.Append(SqlBuilder.BuildTagSelect(t)); } foreach (var c in criterias.NullToEmpty()) { sql.Append(SqlBuilder.BuildCriteriaSelect(IndexMaps, c)); } sql.Append(SqlBuilder.BuildFromTillDateTimeSelect(fromDateTime, tillDateTime)); sql.Append(SqlBuilder.BuildSortingSelect(Options.DefaultSortColumn)); sql.Append(SqlBuilder.BuildPagingSelect(skip, take, Options.DefaultTakeSize, Options.MaxTakeSize)); //var sql = SqlBuilder.BuildDataSelectByKey(TableName); //tags.NullToEmpty().ForEach(t => sql += SqlBuilder.BuildTagSelect(t)); //criterias.NullToEmpty().ForEach(c => sql += SqlBuilder.BuildCriteriaSelect(IndexMaps, c)); //sql += SqlBuilder.BuildFromTillDateTimeSelect(fromDateTime, tillDateTime); //sql += SqlBuilder.BuildSortingSelect(Options.DefaultSortColumn); //sql += SqlBuilder.BuildPagingSelect(skip, take, Options.DefaultTakeSize, Options.MaxTakeSize); conn.Open(); var results = conn.Query <byte[]>(sql.ToString(), new { key }, buffered: Options.BufferedLoad); if (results == null) { yield break; } foreach (var data in results.Where(data => data != null)) { yield return(new MemoryStream(data.Decompress())); } } }