Ordering result list

17 views
Skip to first unread message

FabioDA

unread,
Jul 8, 2012, 2:12:09 PM7/8/12
to catnap-or...@googlegroups.com
Hi.
I started working on a multi platform project (android / iOS), using catnap as Orm.
Right now I'm developing on Android.  So far so good, considering the short documentation, which made it somewhat of a guesswork to start using it (i'm not too fluent in c#....)
I mean no disrespect to the developer of course... Catnap is really cool, as it reminds me oh Hibernate :)
I added support for the "Like" criteria, as I needed it.
Now I'm trying to find a way to order my result see returned using Criterias, but found no way of doing it.
Is there support for ordering (generating an ORDER BY statement)?

Also, to speed up development, a guide or sample projects would be awesome (a little more than the Tests sources). Is any such thing available?

I'll keep you guys posted on my android development (since I seem to be the only one using catnap for android as opposed as iOS)...

TIA.
Fabio

Tim Scott

unread,
Jul 9, 2012, 3:45:18 PM7/9/12
to catnap-or...@googlegroups.com
Fabio,

Glad to hear that Catnap is working for you and especially that it's working on Android. If it reminds you of Hibernate, it's because it's inspired by nHibernate.  Indeed name "Catnap" is a play on Hibernate -- intended to convey it's light-ness in comparison to nHibernate.

Unfortunately the ICriteria interface does not have a way to specify ORDER BY. You have two choices at present: 

a) sort the resulting IList<T> in memory using Linq
b) use DbCommandSpec to create raw parameterized SQL

I have used mostly (a) because my mobile apps never needed to handle very large results sets.  Option (b) is not as bad as it sounds because Catnap still handles hydrating your entity and such.

Yes, the documentation is certainly a pretty thin.  Did you find the this? https://github.com/timscott/catnap/wiki/Introduction

Adding ordering support to ICriteria would be a great addition.  Regarding that and documentation, Catnap is open source, and we eagerly encourage contributions.  Also, we would be very delighted if someone would put a nice reference project on Github.

Tim

FabioDA

unread,
Jul 10, 2012, 6:33:14 AM7/10/12
to catnap-or...@googlegroups.com
I've read the introduction, and it was nice for starting up.  I was just wishing for something more in-depth.  
I will see what I can come up with for adding ordering to the result set (i already added support for the Like operator, and that was pretty easy to do).  I might be working with larger datasets (in the 1000s of records maybe).
Yes I know I should filter them in the query... :P

Right now I'm using the evaluation version on Mono for Android, and the emulator is pretty slow, so i don't know how sorting with Linq would affect performance.  I plan on buying Mono for android soon, so I can start testing my app on a real device.
I'll start with Linq and see how it handles, then I'll think of something :)

Thank you again for you great work!!  It's really appreciated.

Tim Scott

unread,
Jul 10, 2012, 11:35:24 AM7/10/12
to catnap-or...@googlegroups.com
Fabio,

Cool.  It would be great if you could contribute your LIKE support via a pull request.  The only trick is to make sure it will work across DB implementations.  If there is variability, we might need to extend the adapter interface to handle any differences.

If you want to take a crack at Order support for ICriteria, that would be awesome.  I put a little thought into it.  I would probably create a folder Orders as sibling to Conditions and put a class or classes in there -- perhaps Order with subclasses OrderAscending and OrderDescending.  The API and building the the SQL would live in Criteria<T> class.  Probably add a private collection orders and append to the commandText at build time.  Those are my thoughts.

BTW, I absolutely agree you should sort in the query for large results sets.

Tim

FabioDA

unread,
Jul 12, 2012, 5:18:58 AM7/12/12
to catnap-or...@googlegroups.com
I'll contribute my Like implementation as soon as I can (I will be out of office for the rest of the week).
Actually.. the implementation is quite simple... I copied and pasted the Equal implementation, renamed to Like and changed the operator.  It should work on all databases.
I'm not sure how a pull request work... also I had to create new projects for catnap, as Android Projects, or else it would link the Mono runtime, giving me fits when compiling.
I'm pretty new at Mono, Monodevelopm and Android, but I'm getting more and more efficient as I work.
And I really like it :D

Problably when I'm under the sun for my summer vacation (starting 29th of July) I will give some tought at the Order implementation... I think I really need to learn your class structure first.. I haven't looked too much into that yet, as I have a TON of stuff to learn :)

Tim Scott

unread,
Jul 12, 2012, 10:49:28 AM7/12/12
to catnap-or...@googlegroups.com
Fabio,

Cool, looking forward to getting your contributions.  Here's how to do pull requests: https://help.github.com/articles/using-pull-requests.  We'll use the "fork & pull" model.

Tim
Reply all
Reply to author
Forward
0 new messages