public static Db.OeBoundFunctionParameter CreateBoundFunctionParameter(OeQueryContext queryContext) { var expressionBuilder = new OeExpressionBuilder(queryContext.JoinBuilder); Type sourceEntityType = queryContext.EntitySetAdapter.EntityType; IEdmEntitySet sourceEntitySet = OeEdmClrHelper.GetEntitySet(queryContext.EdmModel, queryContext.EntitySetAdapter.EntitySetName); Expression source = OeEnumerableStub.CreateEnumerableStubExpression(sourceEntityType, sourceEntitySet); source = expressionBuilder.ApplyNavigation(source, queryContext.ParseNavigationSegments); IEdmEntitySet targetEntitySet = OeOperationHelper.GetEntitySet(queryContext.ODataUri.Path); if (sourceEntitySet != targetEntitySet) { queryContext.ODataUri.Path = new ODataPath(new EntitySetSegment(targetEntitySet)); } expressionBuilder = new OeExpressionBuilder(queryContext.JoinBuilder); Type targetEntityType = queryContext.EdmModel.GetClrType(targetEntitySet.EntityType()); Expression target = OeEnumerableStub.CreateEnumerableStubExpression(targetEntityType, targetEntitySet); target = expressionBuilder.ApplySelect(target, queryContext); var sourceQueryExpression = new OeQueryExpression(queryContext.EdmModel, sourceEntitySet, source); var targetQueryExpression = new OeQueryExpression(queryContext.EdmModel, targetEntitySet, target) { EntryFactory = expressionBuilder.CreateEntryFactory(targetEntitySet) }; Type boundFunctionParameterType = typeof(Db.OeBoundFunctionParameter <,>).MakeGenericType(new[] { sourceEntityType, targetEntityType }); ConstructorInfo ctor = boundFunctionParameterType.GetConstructor(new[] { typeof(OeQueryExpression), typeof(OeQueryExpression) }); return((Db.OeBoundFunctionParameter)ctor.Invoke(new Object[] { sourceQueryExpression, targetQueryExpression })); }
public Expression CreateExpression(IQueryable query, OeConstantToVariableVisitor constantToVariableVisitor) { Expression expression; var expressionBuilder = new OeExpressionBuilder(EdmModel, EntitySetAdapter.EntityType); expression = Expression.Constant(null, typeof(IEnumerable <>).MakeGenericType(EntitySetAdapter.EntityType)); expression = expressionBuilder.ApplyNavigation(expression, ParseNavigationSegments); expression = expressionBuilder.ApplyFilter(expression, ODataUri.Filter); expression = expressionBuilder.ApplySkipToken(expression, SkipTokenParser, ODataUri.SkipToken); expression = expressionBuilder.ApplyAggregation(expression, ODataUri.Apply); expression = expressionBuilder.ApplySelect(expression, this); expression = expressionBuilder.ApplyOrderBy(expression, ODataUri.OrderBy); expression = expressionBuilder.ApplySkip(expression, ODataUri.Skip, ODataUri.Path); expression = expressionBuilder.ApplyTake(expression, ODataUri.Top, ODataUri.Path); expression = expressionBuilder.ApplyCount(expression, IsCountSegment); if (!IsCountSegment) { EntryFactory = CreateEntryFactory(expressionBuilder); } expression = constantToVariableVisitor.Translate(expression, expressionBuilder.Constants); if (ODataUri.QueryCount.GetValueOrDefault()) { CountExpression = CreateCountExpression(query, expression); } return(SourceVisitor.Translate(query, expression)); }
public Expression CreateExpression(OeConstantToVariableVisitor constantToVariableVisitor) { Expression expression; var expressionBuilder = new OeExpressionBuilder(EdmModel, EntitySetAdapter.EntityType); expression = Expression.Constant(null, typeof(IEnumerable <>).MakeGenericType(EntitySetAdapter.EntityType)); expression = expressionBuilder.ApplyNavigation(expression, ParseNavigationSegments); expression = expressionBuilder.ApplyFilter(expression, ODataUri.Filter); expression = expressionBuilder.ApplySkipToken(expression, SkipTokenNameValues, ODataUri.OrderBy, IsDatabaseNullHighestValue); expression = expressionBuilder.ApplyAggregation(expression, ODataUri.Apply); expression = expressionBuilder.ApplySelect(expression, this); expression = expressionBuilder.ApplyOrderBy(expression, ODataUri.OrderBy); expression = expressionBuilder.ApplySkip(expression, ODataUri.Skip, ODataUri.Path); expression = expressionBuilder.ApplyTake(expression, ODataUri.Top, ODataUri.Path); expression = expressionBuilder.ApplyCount(expression, IsCountSegment); if (!IsCountSegment) { EntryFactory = CreateEntryFactory(expressionBuilder); } if (SkipTokenNameValues != null) { SkipTokenAccessors = OeSkipTokenParser.GetAccessors(expression, ODataUri.OrderBy); } return(constantToVariableVisitor.Translate(expression, expressionBuilder.Constants)); }
public Expression CreateExpression(out IReadOnlyDictionary <ConstantExpression, ConstantNode> constants) { Initialize(); Expression expression; var expressionBuilder = new OeExpressionBuilder(_joinBuilder); IEdmEntitySet entitySet = OeEdmClrHelper.GetEntitySet(EdmModel, EntitySetAdapter.EntitySetName); expression = OeEnumerableStub.CreateEnumerableStubExpression(EntitySetAdapter.EntityType, entitySet); expression = expressionBuilder.ApplyNavigation(expression, ParseNavigationSegments); if (ODataUri.Apply == null) { expression = expressionBuilder.ApplyFilter(expression, ODataUri.Filter); expression = expressionBuilder.ApplySelect(expression, this); } else { expression = expressionBuilder.ApplyAggregation(expression, ODataUri.Apply); expression = expressionBuilder.ApplyFilter(expression, ODataUri.Filter); expression = expressionBuilder.ApplySkipToken(expression, SkipTokenNameValues, ODataUri.OrderBy, IsDatabaseNullHighestValue); //order by aggregation expression = expressionBuilder.ApplyOrderBy(expression, ODataUri.OrderBy); expression = expressionBuilder.ApplySkip(expression, ODataUri.Skip, ODataUri.Path); expression = expressionBuilder.ApplyTake(expression, ODataUri.Top, ODataUri.Path); } if (ODataUri.Path.LastSegment is CountSegment) { expression = expressionBuilder.ApplyCount(expression, true); } else { OePropertyAccessor[] skipTokenAccessors = OeSkipTokenParser.GetAccessors(expression, ODataUri.OrderBy, _joinBuilder); EntryFactory = CreateEntryFactory(expressionBuilder, skipTokenAccessors); } constants = expressionBuilder.Constants; return(expression); }
public Expression CreateExpression(IQueryable query, OeConstantToVariableVisitor constantToVariableVisitor) { Expression expression; var expressionBuilder = new OeExpressionBuilder(EdmModel, EntitySetAdapter.EntityType); expression = Expression.Constant(null, typeof(IEnumerable <>).MakeGenericType(EntitySetAdapter.EntityType)); expression = expressionBuilder.ApplyNavigation(expression, ParseNavigationSegments); expression = expressionBuilder.ApplyFilter(expression, ODataUri.Filter); expression = expressionBuilder.ApplyAggregation(expression, ODataUri.Apply); expression = expressionBuilder.ApplySelect(expression, ODataUri.SelectAndExpand, ODataUri.Path, Headers.MetadataLevel); expression = expressionBuilder.ApplyOrderBy(expression, ODataUri.OrderBy); expression = expressionBuilder.ApplySkip(expression, ODataUri.Skip, ODataUri.Path); expression = expressionBuilder.ApplyTake(expression, ODataUri.Top, ODataUri.Path); expression = expressionBuilder.ApplyCount(expression, IsCountSegment); if (!IsCountSegment) { EntryFactory = CreateEntryFactory(expressionBuilder); } expression = constantToVariableVisitor.Translate(expression, expressionBuilder.Constants); return(SourceVisitor.Translate(query, expression)); }
public Expression CreateExpression(OeConstantToVariableVisitor constantToVariableVisitor) { Expression expression; var expressionBuilder = new OeExpressionBuilder(JoinBuilder); IEdmEntitySet entitySet = OeEdmClrHelper.GetEntitySet(EdmModel, EntitySetAdapter.EntitySetName); expression = OeEnumerableStub.CreateEnumerableStubExpression(EntitySetAdapter.EntityType, entitySet); expression = expressionBuilder.ApplyNavigation(expression, ParseNavigationSegments); expression = expressionBuilder.ApplyFilter(expression, ODataUri.Filter); if (ODataUri.Apply == null) { expression = expressionBuilder.ApplySelect(expression, this); } else { expression = expressionBuilder.ApplySkipToken(expression, SkipTokenNameValues, ODataUri.OrderBy, IsDatabaseNullHighestValue); expression = expressionBuilder.ApplyAggregation(expression, ODataUri.Apply); expression = expressionBuilder.ApplyOrderBy(expression, ODataUri.OrderBy); expression = expressionBuilder.ApplySkip(expression, ODataUri.Skip, ODataUri.Path); expression = expressionBuilder.ApplyTake(expression, ODataUri.Top, ODataUri.Path); } expression = expressionBuilder.ApplyCount(expression, IsCountSegment); if (!IsCountSegment) { EntryFactory = CreateEntryFactory(expressionBuilder); } if (SkipTokenNameValues != null) { SkipTokenAccessors = OeSkipTokenParser.GetAccessors(expression, ODataUri.OrderBy, JoinBuilder); } return(constantToVariableVisitor.Translate(expression, expressionBuilder.Constants)); }