/// <summary> /// Visits the <paramref name="queryModel"/> and generates a <see cref="QueryDescription"/>. /// </summary> /// <param name="queryModel">The query model.</param> /// <returns></returns> /// <remarks></remarks> public QueryDescription VisitAndGenerateQueryDescription(Remotion.Linq.QueryModel queryModel) { // Reset description builder _queryDescription = new QueryDescriptionBuilder(); VisitQueryModel(queryModel); // If we haven't found any result operators then add one just saying sequence if (!_queryDescription.ResultFilters.Any()) { _queryDescription.AddResultFilter(GetResultType(queryModel), ResultFilterType.Sequence, -1); } return(_queryDescription); }
/// <summary> /// Visits the result operator. /// </summary> /// <param name="resultOperator">The result operator.</param> /// <param name="queryModel">The query model.</param> /// <param name="index">The index.</param> /// <remarks></remarks> public override void VisitResultOperator(ResultOperatorBase resultOperator, Remotion.Linq.QueryModel queryModel, int index) { if (typeof(CountResultOperator).IsAssignableFrom(resultOperator.GetType())) { //_queryDescription.SetResultFilterClause(queryModel.MainFromClause.ItemType, ResultFilterType.Count, 0); _queryDescription.AddResultFilter(queryModel.MainFromClause.ItemType, ResultFilterType.Count, 0); } if (typeof(SingleResultOperator).IsAssignableFrom(resultOperator.GetType())) { var op = resultOperator as SingleResultOperator; var filter = op.ReturnDefaultWhenEmpty ? ResultFilterType.SingleOrDefault : ResultFilterType.Single; //_queryDescription.SetResultFilterClause(queryModel.MainFromClause.ItemType, filter, 0); _queryDescription.AddResultFilter(queryModel.MainFromClause.ItemType, filter, 0); } if (typeof(TakeResultOperator).IsAssignableFrom(resultOperator.GetType())) { var firstResultOperator = resultOperator as TakeResultOperator; var countExpression = firstResultOperator.Count as ConstantExpression; var count = Convert.ToInt32(countExpression.Value); //_queryDescription.SetTakeResultFilter(queryModel.MainFromClause.ItemType, count); _queryDescription.AddTakeResultFilter(queryModel.MainFromClause.ItemType, count); } var skipResultOp = resultOperator as SkipResultOperator; if (skipResultOp != null) { var countExpression = skipResultOp.Count as ConstantExpression; var count = Convert.ToInt32(countExpression.Value); //_queryDescription.SetSkipResultFilter(queryModel.MainFromClause.ItemType, count); _queryDescription.AddSkipResultFilter(queryModel.MainFromClause.ItemType, count); } if (resultOperator is AnyResultOperator) { //_queryDescription.SetResultFilterClause(queryModel.MainFromClause.ItemType, ResultFilterType.Any, 0); _queryDescription.AddResultFilter(queryModel.MainFromClause.ItemType, ResultFilterType.Any, 0); } var allResultOp = resultOperator as AllResultOperator; if (allResultOp != null) { var criteriaExpression = this.GetCriteriaExpression(queryModel, allResultOp.Predicate); _queryDescription.SetCriteria(criteriaExpression); //_queryDescription.SetResultFilterClause(queryModel.MainFromClause.ItemType, ResultFilterType.All, 0); _queryDescription.AddResultFilter(queryModel.MainFromClause.ItemType, ResultFilterType.All, 0); } var firstResultOp = resultOperator as FirstResultOperator; if (firstResultOp != null) { //this._queryDescription.SetResultFilterClause( // queryModel.MainFromClause.ItemType, // firstResultOp.ReturnDefaultWhenEmpty ? ResultFilterType.FirstOrDefault : ResultFilterType.First, // 0); this._queryDescription.AddResultFilter( queryModel.MainFromClause.ItemType, firstResultOp.ReturnDefaultWhenEmpty ? ResultFilterType.FirstOrDefault : ResultFilterType.First, 0); } var lastResultOp = resultOperator as LastResultOperator; if (lastResultOp != null) { this._queryDescription.AddResultFilter( queryModel.MainFromClause.ItemType, lastResultOp.ReturnDefaultWhenEmpty ? ResultFilterType.LastOrDefault : ResultFilterType.Last, 0); } base.VisitResultOperator(resultOperator, queryModel, index); }