예제 #1
0
        /// <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);
        }
예제 #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>Executes the query represented by a specified expression tree.</summary>
        /// <param name="expression">An expression tree that represents a LINQ query.</param>
        /// <returns>The value that results from executing the specified query.</returns>
        public object Execute(Expression expression)
        {
            string hash = _aux.IsHashRequired ? expression.CalculateHash() : string.Empty;
            object result;

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

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

            return(result);
        }