private void Compile() { if (_query == null) { _query = SnExpression.BuildQuery(_queryable.Expression, typeof(T), _queryable.ContextPath, _queryable.ChildrenDefinition); } }
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; } }
//================================================================================================================================================== public LucQuery GetCompiledQuery() { var q = SnExpression.BuildQuery(this.Expression, typeof(T), this.ContextPath, this.ChildrenDefinition); return(q); }
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>"); }
internal static LucQuery GetLucQuery(Expression expr, bool autoFiltersEnabled, bool lifespanEnabled, ChildrenDefinition childrenDef, string contextPath) { return(SnExpression.BuildQuery(expr, typeof(T), contextPath, childrenDef)); }