Search code examples
asp.netpaginationsubsonic

asp.net subsonic 2.2 paging linked table collection


I'm creating a small forum for my CMS and I'm using subsonic 2.2 as my DAL. I'm loading my theads like this:

DAL.ForumThread item = DAL.ForumThread.FetchByID(id);

In my database my ForumPosts table looks like this:

ForumPostID | ThreadID | Description | UserID | CreatedOn| etc

So now when I have my DAL.ForumThread item I can load the connected post collection by using:

item.ForumPosts();

This all works great, but the problem is that I'm using serverside paging and want to add some additional select parameters too like showing only active records.

Is this even possible when using SubSonic 2.2 ? The workaround I have now is just creating a new SubSonic.Query and select the posts by threadid and there I can set pageindex and pagesize without problems but I think this can be done easier?

I also would like to know if it makes any difference performance wise by just using item.ForumPosts() or starting a new query, I think the forumposts are already in the ForumThreads collection and don't require a new database call right?

I hope someone can point me in the right direction! Thank you for your time and merry christmas.

Kind regards, Mark


Solution

  • This goes a bit late, but. You can instead of using the Query tool use something like this:

    ForumPostsCollection posts = new ForumPostsCollection().Where(ForumPosts.Columns.ThreadId,1).Load();
    

    You can use as many parameters as you want just repeat the where clause like:

    ForumPostsCollection posts = new ForumPostsCollection().Where(ForumPosts.Columns.ThreadId,1).Where(ForumPosts.Active,true).Load();
    

    You can even use a comparison in the one of the Where methos overloads.

    A for paged results, I am sure you can do it, but I dont have subsonic here with me atm, and i cannt find anything in the docos for version 2.2, there is something for v3 though.

    About your second question, Subsonic uses Lazy Loading of collections, meaning that when you execute the method ForumPosts, it issues another database call to fecth that collection. The same is not true for Parent entities, the rule here is if its a method eg: ForumPosts() - A new database call is done, it it is a property eg: post.Thread it will be loaded.