Example #1
0
        /// <summary>Executes the strongly-typed query represented by a specified expression tree.</summary>
        /// <param name="expression">An expression tree that represents a LINQ query.</param>
        /// <typeparam name="TResult">The type of the value that results from executing the query.</typeparam>
        /// <returns>The value that results from executing the specified query.</returns>
        public TResult Execute <TResult>(Expression expression)
        {
            string  hash = _aux.IsHashRequired ? expression.CalculateHash() : string.Empty;
            TResult result;

            if (_aux.IsEvaluationNeeded)
            {
                result = _baseQueryProvider.Execute <TResult>(expression);
            }
            else
            {
                result = _aux.Get <TResult>(hash, _description.Description);
            }

            if (_aux.IsTracingNeeded)
            {
                if (_aux.IsEvaluationNeeded)
                {
                    _aux.Query(hash, result, _description.Description ?? $"Obtaining {typeof(TResult)} via O/RM");
                }
                else
                {
                    _aux.Query(hash, "test data", _description.Description ?? $"Obtaining {typeof(TResult)} via O/RM");
                }
            }

            return(result);
        }
Example #2
0
        /// <summary>
        /// Serialize query results as collection of elements of type <typeparamref name="T"/>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns>Query result</returns>
        public IEnumerable <T> As <T>() where T : class
        {
            IEnumerable <T> result;

            if (_a.IsEvaluationNeeded)
            {
                var cq = _runtime.Tooling.Compile(Sql);
                using (var t = _a.GetQueryTransaction())
                {
                    result = _runtime.DoQuery <T>(cq.Query, cq.Parameters);
                    t.Commit();
                }
            }
            else
            {
                result = _a.Get <IEnumerable <T> >(Sql.Hash(), _description);
            }

            if (_a.IsTracingNeeded)
            {
                _a.Query(Sql.Hash(), result, _description);
            }

            return(result);
        }
        /// <summary>Returns an enumerator that iterates through the collection.</summary>
        /// <returns>An enumerator that can be used to iterate through the collection.</returns>
        public IEnumerator <T> GetEnumerator()
        {
            var             hash = _aux.IsHashRequired ? Expression.CalculateHash() : string.Empty;
            IEnumerator <T> result;
            IEnumerable <T> data = null;

            if (_aux.IsEvaluationNeeded)
            {
                result = _baseQueryable.GetEnumerator();
            }
            else
            {
                data   = _aux.Get <IEnumerable <T> >(hash, _description.Description);
                result = data.GetEnumerator();
            }

            if (_aux.IsTracingNeeded)
            {
                if (_aux.IsEvaluationNeeded)
                {
                    result = new HookEnumerator <T>(hash, result, _aux, _description);
                }
                else
                {
                    _aux.Query(hash, data, _description.Description);
                }
            }

            return(result);
        }