internal OrderByJoinCollection Clone() { OrderByJoinCollection clone = new OrderByJoinCollection(); foreach( OrderByJoin item in this.InnerList ) { clone.Add(item.Clone()); } return clone; }
internal OrderByJoinCollection Clone() { OrderByJoinCollection clone = new OrderByJoinCollection(); foreach (OrderByJoin item in this.InnerList) { clone.Add(item.Clone()); } return(clone); }
private OrderByItem ParseItem(OPathLexer lexer, EntityMap entity, OrderByJoinCollection joins, OrderByJoin parentJoin) { Yytoken token = lexer.CurrentToken; if (token.Type != TokenType.IDENT) { throw new OPathException("'" + token.Text + "' encountered where a property or relationship was expected in sort expression '" + _expression + "'."); } string propertyName = token.Text; token = lexer.Lex(); if (token == null) { FieldMap field; try { field = entity.GetFieldMap(propertyName); } catch { throw new OPathException(string.Format("The specified property '{0}' in the sort '{1}' is not defined in the entity map for type '{2}'.", propertyName, _expression, entity.Type)); } return(new OrderByItem(propertyName, field, true, parentJoin)); } if (token.Type != TokenType.PERIOD) { if (token.Type != TokenType.ASCEND && token.Type != TokenType.DESCEND && token.Type != TokenType.COMMA) { throw new OPathException("'" + token.Text + "' is not valid in sort expression '" + _expression + "'."); } FieldMap field; try { field = entity.GetFieldMap(propertyName); } catch { throw new OPathException(string.Format("The specified property '{0}' in the sort '{1}' is not defined in the entity map for type '{2}'.", propertyName, _expression, entity.Type)); } bool ascending = (token.Type != TokenType.DESCEND); if (token.Type != TokenType.COMMA) { lexer.MoveToNext(); } lexer.MoveToNext(); return(new OrderByItem(propertyName, field, ascending, parentJoin)); } else // dot operator (.) { token = lexer.Lex(); if (token == null) { throw new OPathException("End of expression encountered where a property or relationship was expected in sort expression '" + _expression + "'."); } if (token.Type != TokenType.IDENT) { throw new OPathException("'" + token.Text + "' encountered where a property or relationship was expected in sort expression '" + _expression + "'."); } RelationMap relation = entity.Relation(propertyName); if (relation == null) { throw new OPathException(string.Format("The specified relationship '{0}' in the sort expression '{1}' is not defined in the entity map for type '{2}'.", propertyName, _expression, entity.Type)); } if (relation.Relationship != Relationship.Parent) { throw new Exception("Relationship '" + relation.Alias + "' is not a ManyToOne relation. Only ManyToOne relations are allowed in sort expressions."); } EntityMap relEntity = _maps[relation.Type]; OrderByJoin join = joins[propertyName]; if (join == null) { join = new OrderByJoin(relation); joins.Add(join); } // recursive call return(ParseItem(lexer, relEntity, join.NestedJoins, join)); } }
private OrderByItem ParseItem(OPathLexer lexer, EntityMap entity, OrderByJoinCollection joins, OrderByJoin parentJoin) { Yytoken token = lexer.CurrentToken; if( token.Type != TokenType.IDENT ) { throw new OPathException("'" + token.Text + "' encountered where a property or relationship was expected in sort expression '" + _expression + "'."); } string propertyName = token.Text; token = lexer.Lex(); if( token == null ) { FieldMap field; try { field = entity.GetFieldMap(propertyName); } catch { throw new OPathException(string.Format("The specified property '{0}' in the sort '{1}' is not defined in the entity map for type '{2}'.", propertyName, _expression, entity.Type)); } return new OrderByItem(propertyName, field, true, parentJoin); } if( token.Type != TokenType.PERIOD ) { if( token.Type != TokenType.ASCEND && token.Type != TokenType.DESCEND && token.Type != TokenType.COMMA ) { throw new OPathException("'" + token.Text + "' is not valid in sort expression '" + _expression + "'."); } FieldMap field; try { field = entity.GetFieldMap(propertyName); } catch { throw new OPathException(string.Format("The specified property '{0}' in the sort '{1}' is not defined in the entity map for type '{2}'.", propertyName, _expression, entity.Type)); } bool ascending = (token.Type != TokenType.DESCEND); if( token.Type != TokenType.COMMA ) { lexer.MoveToNext(); } lexer.MoveToNext(); return new OrderByItem(propertyName, field, ascending, parentJoin); } else // dot operator (.) { token = lexer.Lex(); if( token == null ) { throw new OPathException("End of expression encountered where a property or relationship was expected in sort expression '" + _expression + "'."); } if( token.Type != TokenType.IDENT ) { throw new OPathException("'" + token.Text + "' encountered where a property or relationship was expected in sort expression '" + _expression + "'."); } RelationMap relation = entity.Relation(propertyName); if( relation == null ) { throw new OPathException(string.Format("The specified relationship '{0}' in the sort expression '{1}' is not defined in the entity map for type '{2}'.", propertyName, _expression, entity.Type)); } if( relation.Relationship != Relationship.Parent ) { throw new Exception("Relationship '" + relation.Alias + "' is not a ManyToOne relation. Only ManyToOne relations are allowed in sort expressions."); } EntityMap relEntity = _maps[relation.Type]; OrderByJoin join = joins[propertyName]; if( join == null ) { join = new OrderByJoin(relation); joins.Add(join); } // recursive call return ParseItem(lexer, relEntity, join.NestedJoins, join); } }