New Posts New Posts RSS Feed: OrderBy
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

OrderBy

 Post Reply Post Reply
Author
evanian View Drop Down
Newbie
Newbie


Joined: 23-Apr-2010
Posts: 7
Post Options Post Options   Quote evanian Quote  Post ReplyReply Direct Link To This Post Topic: OrderBy
    Posted: 18-May-2010 at 9:17am
Is it possible to OrderBy a spanned column in an RdbQuery?  What I would like to do is this:

            // Query
            _query = new RdbQuery(typeof(AS400Client));

            // Where clause
            _query.AddClause(    AS400Client.FirstNameEntityColumn,
                                EntityQueryOp.EQ,
                                "David");

            // Add span to other table
            _query.AddSpan(EntityRelations.AS400Workplace_AS400Client);

            // Add orderby on column in *related* table
            EntityOrderBy orderBy = new EntityOrderBy(AS400Workplace.DescriptionEntityColumn, ListSortDirection.Descending);

            _query.ClearOrderBy();           
            _query.AddOrderBy(orderBy);
           
            // Get the clients
            PersistenceManager pm = PersistenceManager.DefaultManager;
            _clients = pm.GetEntities<AS400Client>(_query);  


Of course, I get an error:  "Cannot find column Description."   Is there any way of doing this?

(The reason why I'm not simply defining the query as being of the AS400Workplace type is that I want, potentially, to order by columns in either table, dynamically, depending on user input).
Back to Top
IdeaBlade View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 30-May-2007
Location: United States
Posts: 353
Post Options Post Options   Quote IdeaBlade Quote  Post ReplyReply Direct Link To This Post Posted: 19-May-2010 at 5:06pm
You can't order by a spanned column because the EntityList returned by the query only contains the primary Entity type (AS400Client in your case).  You're trying to sort a collection of AS400Client entities on a column that doesn't exist on the AS400Client entity.

The effect of the span is simply to load the AS400Workplace into the cache as a byproduct of your query for AS400Clients.

If you want an entity that combines the columns of AS400Clients and AS400Workplace, you might want to create a view in your database and then base a new entity type on that.  However, that tends to become problematic if you need to change and save the retrieved entities.

You could probably write an IComparer<T> that would sort AS400Clients by a column on the related AS400Workplace (assuming that's a 1-1 relationship). See the example "Reusable MultiProperty Sorter" (and specifically the file MultiPropertyComparer.cs) under the BindableList topic in the 200 Intermediate Learning Units for an example of a custom IComparer<T>

Back to Top
evanian View Drop Down
Newbie
Newbie


Joined: 23-Apr-2010
Posts: 7
Post Options Post Options   Quote evanian Quote  Post ReplyReply Direct Link To This Post Posted: 20-May-2010 at 6:08am
Helpful ideas, thanks!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down