private IEnumerable <IEdmEntityObject> DateNotEquals(IEnumerable <IEdmEntityObject> items, string leftAttributeName, string rightAttributeName, object leftAttributeValue, object rightAttributeValue, EdmPrimitiveTypeKind leftAttributeType, SingleValueNode left) { var typename = ""; if (left.GetType().Name == "SingleValueFunctionCallNode") { typename = ((SingleValueFunctionCallNode)left).Name.ToString(); } else { typename = "default"; } switch (leftAttributeType) { case EdmPrimitiveTypeKind.DateTimeOffset: if (typename == "year") { items = items.Where((x) => { var leftAttribute = Convert.ToDateTime(GetPropertyValue(x, leftAttributeName, leftAttributeValue)); var rightAttribute = GetPropertyValue(x, rightAttributeName, rightAttributeValue); return(!string.Equals(leftAttribute.Year.ToString(), rightAttribute.ToString())); }); } else if (typename == "month") { items = items.Where((x) => { var leftAttribute = Convert.ToDateTime(GetPropertyValue(x, leftAttributeName, leftAttributeValue)); var rightAttribute = GetPropertyValue(x, rightAttributeName, rightAttributeValue); return(!string.Equals(leftAttribute.Month.ToString(), rightAttribute.ToString())); }); } else if (typename == "day") { items = items.Where((x) => { var leftAttribute = Convert.ToDateTime(GetPropertyValue(x, leftAttributeName, leftAttributeValue)); var rightAttribute = GetPropertyValue(x, rightAttributeName, rightAttributeValue); return(!string.Equals(leftAttribute.Day.ToString(), rightAttribute.ToString())); }); } else if (typename == "default") { items = items.Where((x) => { var leftAttribute = Convert.ToDateTime(GetPropertyValue(x, leftAttributeName, leftAttributeValue).ToString(), new CultureInfo("en-US")); var rightAttribute = Convert.ToDateTime(GetPropertyValue(x, rightAttributeName, rightAttributeValue).ToString(), new CultureInfo("en-US")); return(!string.Equals(leftAttribute.AddMilliseconds(-leftAttribute.Millisecond), rightAttribute.AddMilliseconds(-rightAttribute.Millisecond))); }); } break; } return(items); }
/// <summary> /// Retrieves <see cref="EdmClrProperty" /> from the given <see cref="SingleValueNode" />. /// </summary> /// <param name="node">The node to get the property from.</param> protected EdmClrProperty GetProperty(SingleValueNode node) { if (!(node is SingleValuePropertyAccessNode propertyAccessNode)) { throw new ODataException($"The '{node.GetType().Name}' node is not supported."); } if (!(propertyAccessNode.Property is EdmClrProperty property)) { throw new ODataException($"The '{propertyAccessNode.Property.GetType().Name}' property is not supported."); } if (!(propertyAccessNode.Source is ResourceRangeVariableReferenceNode)) { throw new ODataException($"Nested properties are not supported."); } return(property); }
private ISparqlExpression BuildSparqlFilter(SingleValueNode filterNode, string suffix = "") { NodeFactory nodeFactory = new NodeFactory(); if (filterNode.GetType() == typeof(SingleValueFunctionCallNode)) { return(BuildFunctionExpression(filterNode as SingleValueFunctionCallNode)); } else if (filterNode.GetType() == typeof(SingleValuePropertyAccessNode)) { return(new VariableTerm($"?{(filterNode as SingleValuePropertyAccessNode).Property.Name}{suffix}")); } else if (filterNode.GetType() == typeof(ConstantNode)) { return(new ConstantTerm(CreateLiteralNode(filterNode as ConstantNode))); } else if (filterNode.GetType() == typeof(ConvertNode)) { var convert = filterNode as ConvertNode; if (convert.Source is SingleValueFunctionCallNode) { return(BuildSparqlFilter(convert.Source as SingleValueFunctionCallNode, suffix)); } else if (convert.Source is ConstantNode) { return(new ConstantTerm(CreateLiteralNode(convert.Source as ConstantNode))); } else if (convert.Source is SingleValuePropertyAccessNode) { var varName = (convert.Source as SingleValuePropertyAccessNode).Property.Name; if (varName.ToLower() == "localid") { var node = LiteralExtensions.ToLiteral(NamespaceUri.ToString().Length + 1, nodeFactory); varName = EdmNodeList[EdmNodeList.Count - 1].Name; return((new UnaryExpressionFilter( new SubStrFunction(new StrFunction(new VariableTerm($"?{varName}{suffix}")), (new ConstantTerm(node))))).Expression); } else { return(new VariableTerm($"?{varName}{suffix}")); } } } else if (filterNode.GetType() == typeof(BinaryOperatorNode)) { var binaryOperator = filterNode as BinaryOperatorNode; var left = BuildSparqlFilter(binaryOperator.Left, suffix); var right = BuildSparqlFilter(binaryOperator.Right, suffix); if (binaryOperator.OperatorKind == BinaryOperatorKind.And) { return(new AndExpression(left, right)); } else if (binaryOperator.OperatorKind == BinaryOperatorKind.Or) { return(new OrExpression(left, right)); } else if (binaryOperator.OperatorKind == BinaryOperatorKind.Equal) { return(new EqualsExpression(left, right)); } else if (binaryOperator.OperatorKind == BinaryOperatorKind.NotEqual) { return(new NotEqualsExpression(left, right)); } else if (binaryOperator.OperatorKind == BinaryOperatorKind.GreaterThan) { return(new GreaterThanExpression(left, right)); } else if (binaryOperator.OperatorKind == BinaryOperatorKind.GreaterThanOrEqual) { return(new GreaterThanOrEqualToExpression(left, right)); } else if (binaryOperator.OperatorKind == BinaryOperatorKind.LessThan) { return(new LessThanExpression(left, right)); } else if (binaryOperator.OperatorKind == BinaryOperatorKind.LessThanOrEqual) { return(new LessThanOrEqualToExpression(left, right)); } else if (binaryOperator.OperatorKind == BinaryOperatorKind.Add) { return(new AdditionExpression(left, right)); } else if (binaryOperator.OperatorKind == BinaryOperatorKind.Subtract) { return(new SubtractionExpression(left, right)); } else if (binaryOperator.OperatorKind == BinaryOperatorKind.Divide) { return(new DivisionExpression(left, right)); } else if (binaryOperator.OperatorKind == BinaryOperatorKind.Multiply) { return(new MultiplicationExpression(left, right)); } } else if (filterNode.GetType() == typeof(UnaryOperatorNode)) { var unaryOperator = filterNode as UnaryOperatorNode; if (unaryOperator.OperatorKind == UnaryOperatorKind.Not) { return(new NotEqualsExpression(BuildSparqlFilter(unaryOperator.Operand, suffix), new ConstantTerm(LiteralExtensions.ToLiteral(true, nodeFactory)))); } } return(null); }
public static MemberExpression GetPropertyExpression(OeJoinBuilder joinBuilder, Expression source, Expression parameterExpression, SingleValueNode sortProperty) { if (sortProperty is SingleValuePropertyAccessNode propertyNode) { return(joinBuilder.GetJoinPropertyExpression(source, parameterExpression, propertyNode)); } if (sortProperty is SingleValueOpenPropertyAccessNode openPropertyNode) { var propertyExpression = (MemberExpression)joinBuilder.Visitor.TranslateNode(openPropertyNode); var replaceParameterVisitor = new ReplaceParameterVisitor(joinBuilder.Visitor.Parameter, parameterExpression); return((MemberExpression)replaceParameterVisitor.Visit(propertyExpression)); } throw new InvalidOperationException("Unknown type order by expression " + sortProperty.GetType().Name); }
public static IEdmStructuralProperty GetEdmProperty(SingleValueNode sortProperty, Type propertyType) { if (sortProperty is SingleValuePropertyAccessNode propertyNode) { return((IEdmStructuralProperty)propertyNode.Property); } else if (sortProperty is SingleValueOpenPropertyAccessNode openPropertyNode) { IEdmTypeReference typeReference = OeEdmClrHelper.GetEdmTypeReference(propertyType); return(new EdmStructuralProperty(ModelBuilder.PrimitiveTypeHelper.TupleEdmType, openPropertyNode.Name, typeReference)); } throw new InvalidOperationException("Unknown type order by expression " + sortProperty.GetType().Name); }