internal Expression ProcessSelectExpansion(Expression rootExpression, MethodCallExpression selectExpression) { LambdaExpression operand = (LambdaExpression)((UnaryExpression)selectExpression.Arguments[1]).Operand; operand = (LambdaExpression)PartialEvaluator.Eval(operand); List <ResourceProperty> refPropertiesUsed = GetRefPropertiesUsed(operand); IQueryable <DSResource> source = this.EvaluateByLinqToObjects(selectExpression.Arguments[0]) as IQueryable <DSResource>; foreach (ResourceProperty property in refPropertiesUsed) { ResourceType resourceType = property.ResourceType; DataServiceQueryProvider.ResultSet associatedInstances = this.GetAssociatedInstances(source, property); DataServiceQueryProvider.ResultSet set2 = null; if (this.resultSets.TryGetValue(resourceType.Name, out set2)) { set2.Concat <DSResource>(associatedInstances); } else { this.resultSets[resourceType.Name] = associatedInstances; } } MethodCallExpression expression = new DSMethodTranslatingVisitor(this.resultSets).VisitAndConvert <MethodCallExpression>(selectExpression, "ProcessSelectExpansion"); object obj2 = source.Provider.CreateQuery(expression); var ___Site4 = CallSite <Func <CallSite, Type, MethodCallExpression, object, ExpressionNodeReplacer> > .Create(Microsoft.CSharp.RuntimeBinder.Binder.InvokeConstructor(CSharpBinderFlags.None, typeof(DSLinqQueryProvider), new CSharpArgumentInfo[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.IsStaticType | CSharpArgumentInfoFlags.UseCompileTimeType, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) })); return(___Site4.Target(___Site4, typeof(ExpressionNodeReplacer), selectExpression, Expression.Constant((dynamic)obj2)).Visit(rootExpression)); }
internal Expression ProcessWhereWithResourceRoot(Expression rootExpression, MethodCallExpression whereExpression, bool insideNavPropertyWithGetReferenceCmdlet = false) { ICommand command; LambdaExpression operand = (LambdaExpression)((UnaryExpression)whereExpression.Arguments[1]).Operand; operand = (LambdaExpression)PartialEvaluator.Eval(operand); ResourceType initialResourceType = this.GetInitialResourceType(); EntityMetadata entityMetadatum = this.schema.EntityMetadataDictionary[initialResourceType.FullName]; if (!insideNavPropertyWithGetReferenceCmdlet) { command = DataServiceController.Current.GetCommand(CommandType.Read, this.userContext, initialResourceType, entityMetadatum, this.membershipId); } else { command = new ReferenceInstanceBuilderCommand(initialResourceType, entityMetadatum); } DataServiceQueryProvider.ResultSet resultSet = null; using (command) { operand = this.InvokeFilteredGet(command, initialResourceType, operand, out resultSet); } DSMethodTranslatingVisitor dSMethodTranslatingVisitor = new DSMethodTranslatingVisitor(this.resultSets); operand = dSMethodTranslatingVisitor.VisitAndConvert <LambdaExpression>(operand, "ProcessWhereWithResourceRoot"); Func <DSResource, bool> func = (Func <DSResource, bool>)operand.Compile(); IQueryable <DSResource> dSResources = resultSet.Where <DSResource>((DSResource item) => func(item)).AsQueryable <DSResource>(); ExpressionNodeReplacer expressionNodeReplacer = new ExpressionNodeReplacer(whereExpression, Expression.Constant(dSResources)); Expression expression = expressionNodeReplacer.Visit(rootExpression); return(expression); }
internal object EvaluateByLinqToObjects(Expression expression) { IQueryable <DSResource> dSResources = this.initialResourceRoot.AsQueryable <DSResource>(); DSMethodTranslatingVisitor dSMethodTranslatingVisitor = new DSMethodTranslatingVisitor(this.resultSets); expression = dSMethodTranslatingVisitor.Visit(expression); object obj = null; var genericTypeDef = expression.Type.GetGenericTypeDefinition(); if (!expression.Type.IsGenericType || !(genericTypeDef == typeof(IQueryable <>)) && !(genericTypeDef == typeof(EnumerableQuery <>)) && !(genericTypeDef.Name == "QueryableEnumerable`1")) { obj = dSResources.Provider.Execute(expression); } else { obj = dSResources.Provider.CreateQuery(expression); } return(obj); }