Query Join Help

Topics: Writing modules
Developer
Jul 23, 2011 at 5:11 PM

Hey All,

Im getting stuck with writing this query.. I keep looking at it and my mind is drawing a blank, could someone please give me a hand?

So the Idea is that I can get the LatestPost based on the Forum Id

Forum -> Thread -> Post (Where the container for Thread is a Forum, and for a Post it is a Thread)

I have this, but I know its more or less completely wrong...

public PostPart GetLatestPost(ForumPart forumPart, VersionOptions versionOptions) {
    return _contentManager
        .Query<PostPart, PostPartRecord>(versionOptions)
        .Join<ThreadPartRecord>()
        .Join<ForumPartRecord>().Where(f => f.Id == forumPart.Id)
        .List()
        .LastOrDefault();

Hope someone can help :)

Cheers, Nick

Coordinator
Jul 25, 2011 at 8:16 PM

You could start by explaining what problem you're facing...

Developer
Jul 25, 2011 at 8:22 PM

The problem is that I keep confusing my self with this query.

A PostPart has a container of ThreadPart and a ThreadPart has a container of ForumPart but how can I join all this up in the above query?

Developer
Jul 26, 2011 at 7:10 PM

Any ideas Bertrand? Do you know you would join these up within the linq query?

Coordinator
Jul 26, 2011 at 7:21 PM

I don't know. I've asked around.

Developer
Jul 26, 2011 at 7:22 PM

Cool thanks alot dude. Let me know if anyone comes back with something.

Developer
Jul 29, 2011 at 10:07 PM

Any luck Bertrand? I thought it might be this??

        public PostPart GetLatestPost(ForumPart forumPart, VersionOptions versionOptions) {
            return _contentManager
                .Query<PostPart, PostPartRecord>(versionOptions)
                .Join<ThreadPartRecord>()
                .Join<CommonPartRecord>().Where(cpr => cpr.Container == forumPart.ContentItem.Record)
                .List()
                .LastOrDefault();
        }
but I am sill getting null... hmm.. The Join between ThreadPartRecord and CommonPartRecord does not seem to be working...

Coordinator
Jul 29, 2011 at 10:13 PM

Yeah, in the current state of ContentManager queries, I'm not optimistic (which clearly sucks). Your best (but evil) bet would probably to go down one level and hit nHibernate directly, using HQL or ICriteria.

Developer
Jul 29, 2011 at 10:28 PM

nooooooooooo... okay no problem, thanks for you help