Exemplo n.º 1
0
 private void Compile()
 {
     if (_query == null)
     {
         _query = SnExpression.BuildQuery(_queryable.Expression, typeof(T), _queryable.ContextPath, _queryable.ChildrenDefinition);
     }
 }
Exemplo n.º 2
0
 private void Compile()
 {
     if (_query == null)
     {
         var q     = LucQuery.Create(SnExpression.GetPathQuery(_queryable.ContextPath, _queryable.SubTree));
         var query = SnExpression.BuildQuery(_queryable.Expression, typeof(T), _queryable.ContextPath, _queryable.ChildrenDefinition);
         query.AddAndClause(q);
         _query = query;
     }
 }
Exemplo n.º 3
0
        //==================================================================================================================================================
        public LucQuery GetCompiledQuery()
        {
            var q = SnExpression.BuildQuery(this.Expression, typeof(T), this.ContextPath, this.ChildrenDefinition);

            return(q);
        }
Exemplo n.º 4
0
        public virtual TResult Execute <TResult>(System.Linq.Expressions.Expression expression)
        {
            int count = 0;

            // in case there is a predefined list of nodes, we do not execute a query (but we still need to build it)
            if (!this.ExecuteQuery)
            {
                count = ChildrenDefinition.BaseCollection.Count();
            }

            var query = SnExpression.BuildQuery(expression, typeof(T), this.ContextPath, this.ChildrenDefinition);

            if (TracingEnabled)
            {
                TraceLog.Append("Expression: ").AppendLine(expression.ToString());
                TraceLog.Append("Query:      ").AppendLine(query.ToString());
                TraceLog.AppendLine("--------------");
            }
            var result = this.ExecuteQuery ? query.Execute() : null;

            if (query.CountOnly)
            {
                if (this.ExecuteQuery)
                {
                    count = query.TotalCount;
                }

                if (query.ExistenceOnly)
                {
                    return((TResult)Convert.ChangeType(count > 0, typeof(TResult)));
                }
                else
                {
                    return((TResult)Convert.ChangeType(count, typeof(TResult)));
                }
            }
            if (this.ExecuteQuery)
            {
                count = result.Count();
            }

            if (count == 0)
            {
                if (query.ThrowIfEmpty)
                {
                    throw new InvalidOperationException("Sequence contains no elements.");
                }
                return(default(TResult));
            }
            if (count == 1)
            {
                if (typeof(Node).IsAssignableFrom(typeof(TResult)))
                {
                    if (this.ExecuteQuery)
                    {
                        return((TResult)Convert.ChangeType(Node.LoadNode(result.First().NodeId), typeof(TResult)));
                    }
                    return((TResult)Convert.ChangeType(ChildrenDefinition.BaseCollection.First(), typeof(TResult)));
                }
                if (this.ExecuteQuery)
                {
                    return((TResult)Convert.ChangeType(Content.Load(result.First().NodeId), typeof(TResult)));
                }
                return((TResult)Convert.ChangeType(Content.Create(ChildrenDefinition.BaseCollection.First()), typeof(TResult)));
            }

            throw new NotImplementedException("SnLinq: ContentSet.Execute<TResult>");
        }
Exemplo n.º 5
0
 internal static LucQuery GetLucQuery(Expression expr, bool autoFiltersEnabled, bool lifespanEnabled, ChildrenDefinition childrenDef, string contextPath)
 {
     return(SnExpression.BuildQuery(expr, typeof(T), contextPath, childrenDef));
 }