/// <summary> /// Executes the query on the cache and returns the result as generic IEnumerable. /// </summary> /// <typeparam name="T">The generic type of the collection</typeparam> /// <param name="query">The query to be executed. </param> /// <returns>Returns the result set of the query after executing it in the cache. In case of no result return the /// default values.</returns> public static IEnumerable<T> FromCacheOnly<T>(this IQueryable<T> query) where T : class { Logger.Log( "Performing FromCacheOnly for " + query.ToString() + ".", LogLevel.Trace ); string oqlQuery = OQLBuilder.ExpressionToOQL(query.GetDbContext(), query.Expression, out OQLBuilder oqlBuilder); Logger.Log("OQL Query Generated: " + oqlQuery, LogLevel.Debug); return new NCacheOqlEnumerable<T>( NCacheOqlEnumerable<T>.EnumerableType.Normal, QueryCacheManager.Cache.NCacheInstance.ExecuteReader(oqlQuery, new Hashtable(), true) ); }
/// <summary> /// Executes the query on the cache and returns the result as generic type. /// </summary> /// <typeparam name="T">The generic type of the result.</typeparam> /// <param name="query">The query to be executed.</param> /// <returns>Returns the result of the query after executing it in the cache. In case of no result return the /// default value.</returns> public static T FromCacheOnly <T>(this QueryDeferred <T> query) { string oqlQuery = OQLBuilder.ExpressionToOQL(query.Query.GetDbContext(), query.Expression, out OQLBuilder builder); Logger.Log("OQL Query Generated for deferred operation: " + oqlQuery, Microsoft.Extensions.Logging.LogLevel.Debug); IEnumerable <T> enumerable = new NCacheOqlEnumerable <T>( NCacheOqlEnumerable <T> .EnumerableType.Deferred, QueryCacheManager.Cache.NCacheInstance.ExecuteReader(oqlQuery, new System.Collections.Hashtable(), true) ); string aggregateUsed = builder.GetAggregateUsed(); if (aggregateUsed != null) { aggregateUsed = aggregateUsed.Split('(')[0].ToLower(); Logger.Log("Aggregate function used: " + aggregateUsed, Microsoft.Extensions.Logging.LogLevel.Trace); if (aggregateUsed.Equals("count")) { dynamic expando = new ExpandoObject(); var list = enumerable.ToList(); if (list.Count == 1) { expando.Value = list[0]; } else { expando.Value = list.Count; } return((T)expando.Value); } } return(enumerable.FirstOrDefault()); }