Example #1
0
        // Thanks to both Allan Ritchie ([email protected])
        // and Gerrod Thomas (http://www.Gerrod.com) for advice and code
        public object Resync(object entityObject)
        {
            EntityMap entity = this.mappings[entityObject.GetType()];

            for (int index = 0; index < entity.RelationCount; index++)
            {
                RelationMap   relation = entity.Relation(index);
                object        member   = this[entityObject].GetField(relation.Member);
                ILoadOnDemand lazy     = member as ILoadOnDemand;

                if (lazy != null)
                {
                    if (lazy.IsLoaded)
                    {
                        lazy.Resync();
                    }
                }
            }
            this.EndTracking(entityObject);

            EntityKey entityKey = new EntityKey(this, entityObject, true);

            return(this.GetObject(entityObject.GetType(), entityKey.Value, true));
        }
Example #2
0
        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);
            }
        }