/// <summary> /// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will /// return this expression. /// </summary> /// <param name="projectionBindingExpression"> The <see cref="ProjectionBindingExpression" /> property of the result. </param> /// <returns> This expression if no children changed, or an expression with the updated children. </returns> public virtual CollectionResultExpression Update(ProjectionBindingExpression projectionBindingExpression) { Check.NotNull(projectionBindingExpression, nameof(projectionBindingExpression)); return(projectionBindingExpression != ProjectionBindingExpression ? new CollectionResultExpression(projectionBindingExpression, Navigation, ElementType) : this); }
private object GetProjectionIndex(ProjectionBindingExpression projectionBindingExpression) { return(projectionBindingExpression.ProjectionMember != null ? ((ConstantExpression)_selectExpression.GetMappedProjection(projectionBindingExpression.ProjectionMember)).Value : (projectionBindingExpression.Index != null ? (object)projectionBindingExpression.Index : projectionBindingExpression.IndexMap)); }
/// <summary> /// Creates a new instance of the <see cref="CollectionResultExpression" /> class. /// </summary> /// <param name="projectionBindingExpression"> An expression reprensenting how to get the subquery from SelectExpression to get the elements. </param> /// <param name="navigation"> A navigation associated with this collection, if any. </param> /// <param name="elementType"> The clr type of individual elements in the collection. </param> public CollectionResultExpression( ProjectionBindingExpression projectionBindingExpression, INavigationBase?navigation, Type elementType) { ProjectionBindingExpression = projectionBindingExpression; Navigation = navigation; ElementType = elementType; }
private ShapedQueryExpression AggregateResultShaper( ShapedQueryExpression source, Expression projection, bool throwOnNullResult, Type resultType) { var selectExpression = (SelectExpression)source.QueryExpression; selectExpression.ReplaceProjectionMapping( new Dictionary <ProjectionMember, Expression> { { new ProjectionMember(), projection } }); selectExpression.ClearOrdering(); Expression shaper = new ProjectionBindingExpression(source.QueryExpression, new ProjectionMember(), projection.Type); if (throwOnNullResult) { var resultVariable = Expression.Variable(projection.Type, "result"); shaper = Expression.Block( new[] { resultVariable }, Expression.Assign(resultVariable, shaper), Expression.Condition( Expression.Equal(resultVariable, Expression.Default(projection.Type)), Expression.Throw( Expression.New( typeof(InvalidOperationException).GetConstructors() .Single(ci => ci.GetParameters().Length == 1), Expression.Constant(CoreStrings.NoElements)), resultType), resultType != resultVariable.Type ? Expression.Convert(resultVariable, resultType) : (Expression)resultVariable)); } else if (resultType.IsNullableType()) { shaper = Expression.Convert(shaper, resultType); } source.ShaperExpression = shaper; return(source); }
/// <summary> /// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will /// return this expression. /// </summary> /// <param name="projectionBindingExpression">The <see cref="ProjectionBindingExpression" /> property of the result.</param> /// <returns>This expression if no children changed, or an expression with the updated children.</returns> public virtual CollectionResultExpression Update(ProjectionBindingExpression projectionBindingExpression) => projectionBindingExpression != ProjectionBindingExpression ? new CollectionResultExpression(projectionBindingExpression, Navigation, ElementType) : this;