internal static void Analyze(LambdaExpression e, PathBox pb) { bool num = CommonUtil.IsClientType(e.Body.Type); pb.PushParamExpression(e.Parameters.Last()); if (!num) { NonEntityProjectionAnalyzer.Analyze(e.Body, pb); } else { switch (e.Body.NodeType) { case ExpressionType.MemberInit: EntityProjectionAnalyzer.Analyze((MemberInitExpression)e.Body, pb); break; case ExpressionType.New: throw new NotSupportedException("Construction of entity type instances must use object initializer with default constructor."); case ExpressionType.Constant: throw new NotSupportedException("Referencing of local entity type instances not supported when projecting results."); default: NonEntityProjectionAnalyzer.Analyze(e.Body, pb); break; } } pb.PopParamExpression(); }
private static void AnalyzeResourceExpression(LambdaExpression lambda, ResourceExpression resource) { PathBox pathBox = new PathBox(); Analyze(lambda, pathBox); resource.Projection = new ProjectionQueryOptionExpression(lambda.Body.Type, lambda, pathBox.ProjectionPaths.ToList()); resource.ExpandPaths = pathBox.ExpandPaths.Union(resource.ExpandPaths, StringComparer.Ordinal).ToList(); }
private static void Analyze(MemberInitExpression mie, PathBox pb) { if (CommonUtil.IsClientType(mie.Type)) { EntityProjectionAnalyzer.Analyze(mie, pb); } else { NonEntityProjectionAnalyzer.Analyze(mie, pb); } }
internal static void Analyze(Expression e, PathBox pb) { NonEntityProjectionAnalyzer nonEntityProjectionAnalyzer = new NonEntityProjectionAnalyzer(pb, e.Type); MemberInitExpression memberInitExpression = e as MemberInitExpression; if (memberInitExpression != null) { foreach (MemberBinding binding in memberInitExpression.Bindings) { MemberAssignment memberAssignment = binding as MemberAssignment; if (memberAssignment != null) { nonEntityProjectionAnalyzer.Visit(memberAssignment.Expression); } } } else { nonEntityProjectionAnalyzer.Visit(e); } }
internal static void Analyze(MemberInitExpression mie, PathBox pb) { EntityProjectionAnalyzer entityProjectionAnalyzer = new EntityProjectionAnalyzer(pb, mie.Type); MemberAssignmentAnalysis previous = null; foreach (MemberBinding binding in mie.Bindings) { MemberAssignment memberAssignment = binding as MemberAssignment; entityProjectionAnalyzer.Visit(memberAssignment.Expression); if (memberAssignment != null) { MemberAssignmentAnalysis memberAssignmentAnalysis = MemberAssignmentAnalysis.Analyze(pb.ParamExpressionInScope, memberAssignment.Expression); if (memberAssignmentAnalysis.IncompatibleAssignmentsException != null) { throw memberAssignmentAnalysis.IncompatibleAssignmentsException; } Type memberType = GetMemberType(memberAssignment.Member); Expression[] expressionsBeyondTargetEntity = memberAssignmentAnalysis.GetExpressionsBeyondTargetEntity(); if (expressionsBeyondTargetEntity.Length == 0) { throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Initializing instances of the entity type {0} with the expression {1} is not supported.", memberType, memberAssignment.Expression)); } MemberExpression memberExpression = expressionsBeyondTargetEntity[expressionsBeyondTargetEntity.Length - 1] as MemberExpression; if (memberExpression != null && memberExpression.Member.Name != memberAssignment.Member.Name) { throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Cannot assign the value from the {0} property to the {1} property. When projecting results into a entity type, the property names of the source type and the target type must match for the properties being projected.", memberExpression.Member.Name, memberAssignment.Member.Name)); } memberAssignmentAnalysis.CheckCompatibleAssignments(mie.Type, ref previous); bool flag = CommonUtil.IsClientType(memberType); if (CommonUtil.IsClientType(memberExpression.Type) && !flag) { throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Constructing or initializing instances of the type {0} with the expression {1} is not supported.", memberType, memberAssignment.Expression)); } } } }
private NonEntityProjectionAnalyzer(PathBox pb, Type type) { box = pb; this.type = type; }