/// <inheritdoc /> public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values) { if (pathSegment.SegmentKind == ODataSegmentKinds.Function) { BoundFunctionPathSegment functionSegment = (BoundFunctionPathSegment)pathSegment; if (FunctionName == functionSegment.FunctionName) { var enumNames = functionSegment.Function.Parameters.Where(p => p.Type.IsEnum()).Select(p => p.Name); if (KeyValuePathSegmentTemplate.TryMatch(ParameterMappings, functionSegment.Values, values, enumNames)) { foreach (KeyValuePair<string, string> nameAndValue in functionSegment.Values) { string name = nameAndValue.Key; object value = functionSegment.GetParameterValue(name); //ProcedureRoutingConventionHelpers.AddFunctionParameters(functionSegment.Function, name, // value, values, values, ParameterMappings); throw new NotImplementedException("ProcedureRoutingConventionHelpers.AddFunctionParameters"); } return true; } } } return false; }
/// <inheritdoc /> public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values) { if (pathSegment.SegmentKind == ODataSegmentKinds.DynamicProperty) { var dynamicPropertyPathSegment = (DynamicPropertyPathSegment)pathSegment; // If we're treating the property name as a parameter store the provided name in our values collection // using the name from the template as the key. if (TreatPropertyNameAsParameterName) { //values[PropertyName] = dynamicPropertyPathSegment.PropertyName; //values[ODataParameterValue.ParameterValuePrefix + PropertyName] = // new ODataParameterValue(dynamicPropertyPathSegment.PropertyName, // EdmLibHelpers.GetEdmPrimitiveTypeReferenceOrNull(typeof(string))); //return true; throw new NotImplementedException("DynamicPropertyPathSegmentTemplate"); } if (PropertyName == dynamicPropertyPathSegment.PropertyName) { return true; } } return false; }
/// <inheritdoc /> public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values) { if (pathSegment.SegmentKind == ODataSegmentKinds.Key) { KeyValuePathSegment keySegment = (KeyValuePathSegment)pathSegment; return TryMatch(ParameterMappings, keySegment.Values, values, null); } return false; }
/// <inheritdoc/> public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values) { if (pathSegment.SegmentKind == ODataSegmentKinds.Cast) { CastPathSegment castSegment = (CastPathSegment)pathSegment; return castSegment.CastType == CastType && castSegment.CastTypeName == CastTypeName; } return false; }
private void HandleNavigationPathSegment(ODataPathSegment segment) { var navigationSegment = (NavigationPathSegment)segment; var entityParameterExpression = Expression.Parameter(this.currentType); var navigationPropertyExpression = Expression.Property(entityParameterExpression, navigationSegment.NavigationPropertyName); this.currentEntityType = navigationSegment.NavigationProperty.ToEntityType(); if (navigationSegment.NavigationProperty.TargetMultiplicity() == EdmMultiplicity.Many) { // get the element type of the target // (the type should be an EntityCollection<T> for navigation queries). this.currentType = navigationPropertyExpression.Type.GetEnumerableItemType(); // need to explicitly define the delegate type as IEnumerable<T> Type delegateType = typeof(Func<,>).MakeGenericType( queryable.ElementType, typeof(IEnumerable<>).MakeGenericType(this.currentType)); LambdaExpression selectBody = Expression.Lambda(delegateType, navigationPropertyExpression, entityParameterExpression); this.queryable = ExpressionHelpers.SelectMany(this.queryable, selectBody, this.currentType); } else { this.currentType = navigationPropertyExpression.Type; LambdaExpression selectBody = Expression.Lambda(navigationPropertyExpression, entityParameterExpression); this.queryable = ExpressionHelpers.Select(this.queryable, selectBody); } }
private void HandlePropertyAccessPathSegment(ODataPathSegment segment) { var propertySegment = (PropertyAccessPathSegment)segment; var entityParameterExpression = Expression.Parameter(this.currentType); var structuralPropertyExpression = Expression.Property(entityParameterExpression, propertySegment.PropertyName); if (propertySegment.Property.Type.IsCollection()) { // Produces new query like 'queryable.SelectMany(param => param.PropertyName)'. // Suppose 'param.PropertyName' is of type 'IEnumerable<T>', the type of the // resulting query would be 'IEnumerable<T>' too. this.currentType = structuralPropertyExpression.Type.GetEnumerableItemType(); var delegateType = typeof(Func<,>).MakeGenericType( this.queryable.ElementType, typeof(IEnumerable<>).MakeGenericType(this.currentType)); var selectBody = Expression.Lambda(delegateType, structuralPropertyExpression, entityParameterExpression); this.queryable = ExpressionHelpers.SelectMany(this.queryable, selectBody, this.currentType); } else { // Produces new query like 'queryable.Select(param => param.PropertyName)'. this.currentType = structuralPropertyExpression.Type; LambdaExpression selectBody = Expression.Lambda(structuralPropertyExpression, entityParameterExpression); this.queryable = ExpressionHelpers.Select(this.queryable, selectBody); } }
private void HandleValuePathSegment(ODataPathSegment segment) { this.IsValuePathSegmentPresent = true; }
private void HandleKeyValuePathSegment(ODataPathSegment segment) { var keySegment = (KeyValuePathSegment)segment; var parameterExpression = Expression.Parameter(this.currentType, DefaultNameOfParameterExpression); var keyValues = GetPathKeyValues(keySegment, this.currentEntityType); BinaryExpression keyFilter = null; foreach (KeyValuePair<string, object> keyValuePair in keyValues) { var equalsExpression = CreateEqualsExpression(parameterExpression, keyValuePair.Key, keyValuePair.Value); keyFilter = keyFilter == null ? equalsExpression : Expression.And(keyFilter, equalsExpression); } var whereExpression = Expression.Lambda(keyFilter, parameterExpression); this.queryable = ExpressionHelpers.Where(this.queryable, whereExpression, this.currentType); }
/// <inheritdoc/> public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values) { if (pathSegment.SegmentKind == ODataSegmentKinds.EntitySet) { EntitySetPathSegment entitySetSegment = (EntitySetPathSegment)pathSegment; return entitySetSegment.EntitySetBase == EntitySetBase && entitySetSegment.EntitySetName == EntitySetName; } return false; }
private void HandleCountPathSegment(ODataPathSegment segment) { this.IsCountPathSegmentPresent = true; }
/// <inheritdoc/> public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values) { if (pathSegment.SegmentKind == ODataSegmentKinds.Navigation) { NavigationPathSegment navigationSegment = (NavigationPathSegment)pathSegment; return navigationSegment.NavigationProperty == NavigationProperty && navigationSegment.NavigationPropertyName == NavigationPropertyName; } return false; }
/// <inheritdoc/> public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values) { return pathSegment.SegmentKind == ODataSegmentKinds.DynamicProperty && ((DynamicPropertyPathSegment)pathSegment).PropertyName == PropertyName; }
/// <inheritdoc/> public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values) { if (pathSegment.SegmentKind == ODataSegmentKinds.Action) { BoundActionPathSegment actionSegment = (BoundActionPathSegment)pathSegment; return actionSegment.Action == Action && actionSegment.ActionName == ActionName; } return false; }
/// <inheritdoc /> public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values) { if (pathSegment.SegmentKind == ODataSegmentKinds.UnboundFunction) { UnboundFunctionPathSegment functionSegment = (UnboundFunctionPathSegment)pathSegment; return functionSegment.Function == Function && functionSegment.FunctionName == FunctionName; } return false; }
/// <inheritdoc/> public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values) { return false; }
/// <inheritdoc/> public override bool TryMatch(ODataPathSegment pathSegment, IDictionary <string, object> values) { return(pathSegment.SegmentKind == ODataSegmentKinds.Batch); }
/// <inheritdoc/> public override bool TryMatch(ODataPathSegment pathSegment, IDictionary <string, object> values) { return(false); }
/// <inheritdoc/> public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values) { if (pathSegment.SegmentKind == ODataSegmentKinds.Property) { PropertyAccessPathSegment propertySegment = (PropertyAccessPathSegment)pathSegment; return propertySegment.Property == Property && propertySegment.PropertyName == PropertyName; } return false; }
private void HandleUnboundFunctionPathSegment(ODataPathSegment segment) { var unboundFunctionPathSegment = (UnboundFunctionPathSegment)segment; var functionImport = unboundFunctionPathSegment.Function; var entityTypeRef = functionImport.Function.ReturnType.AsEntity(); this.currentEntityType = entityTypeRef == null ? null : entityTypeRef.EntityDefinition(); object[] queryArgs = null; if (functionImport.Function.Parameters.Any()) { queryArgs = functionImport.Function.Parameters.Select( p => unboundFunctionPathSegment.GetParameterValue(p.Name)).ToArray(); } this.queryable = this.api.Source(functionImport.Name, queryArgs); this.currentType = queryable.ElementType; }
private void HandleEntitySetPathSegment(ODataPathSegment segment) { var entitySetPathSegment = (EntitySetPathSegment)segment; var entitySet = entitySetPathSegment.EntitySetBase; this.currentEntityType = entitySet.EntityType(); this.queryable = this.api.Source(entitySet.Name, (object[])null); this.currentType = this.queryable.ElementType; }
/// <inheritdoc/> public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values) { if (pathSegment.SegmentKind == ODataSegmentKinds.Singleton) { SingletonPathSegment singletonSegment = (SingletonPathSegment)pathSegment; return singletonSegment.Singleton == Singleton && singletonSegment.SingletonName == SingletonName; } return false; }
/// <inheritdoc/> public override bool TryMatch(ODataPathSegment pathSegment, IDictionary<string, object> values) { return pathSegment.SegmentKind == ODataSegmentKinds.Batch; }
private void HandleSingletonPathSegment(ODataPathSegment segment) { var singletonPathSegment = (SingletonPathSegment)segment; var singleton = singletonPathSegment.Singleton; this.currentEntityType = singleton.EntityType(); this.queryable = this.api.Source(singleton.Name, (object[])null); this.currentType = this.queryable.ElementType; }