Complex projector sort criterion - is this possible?

Topics: Writing modules
Nov 29, 2012 at 7:49 PM
Edited Nov 29, 2012 at 8:17 PM

So, I have some model relations that look like this:

public class PopularityPartRecord : ContentPartRecord {
    public virtual ICollection<PopularityResultRecord> Results { get; set; }
}

 

public class PopularityResultRecord {
    public virtual int Id { get; set; }
    public virtual string HitType { get; set; }
    public virtual string Calculus { get; set; }
    public virtual decimal Day { get; set; }
    public virtual decimal Week { get; set; }
    public virtual decimal Month { get; set; }
    public virtual decimal AllTime { get; set; }
}

 

As you can see, I am attempting to gather statstics about content over various time periods so I can use it to sort by. I can have different metrics for doing so, for instance Total Comments in the last week, Total Views in the past month, etc. If I were going to write SQL to order content by total view count in the last month, I would write something similar to this:

 

SELECT ContentItemRecord c1
LEFT JOIN PopularityResultRecord r1 ON
    r1.PopularityPartRecord_Id = c1.Id AND
    r1.HitType = 'Views' AND
    r1.Calculus = 'Total'
ORDER BY r1.Month DESC

 

(This assumes that NHibernate places the appropriate reference column in the table)

I could also do this through LINQ queries.

I can't see a way to do anything like this using Hql joins or IAliasFactory, so I can't provide a nice projection filter form to select your sort criteria with. Is there anything that I'm missing or can the interfaces really just not do this?

 

Edit: It looks like the DefaultHqlQuery currently has no way of generating join expressions. Oh well.

Developer
Jan 19, 2013 at 12:48 PM

Are you sure?

var query = _contentManager.HqlQuery().ForPart<DocumentPart>().Join(alias => alias.ContentPartRecord<TitlePartRecord>());

 

Jan 22, 2013 at 5:34 PM
Edited Jan 22, 2013 at 6:50 PM

http://orchard.codeplex.com/discussions/350727

Jan 24, 2013 at 7:47 AM
sfmskywalker wrote:

Are you sure?

var query = _contentManager.HqlQuery().ForPart<DocumentPart>().Join(alias => alias.ContentPartRecord<TitlePartRecord>());

 

Yes, it can generate joins but it can not do so as a complex expression, such as having multiple criteria in the join like in the sql example I have above.

 

I checked the HqlQuery code to verify this. Joins are limited to a single equivalence comparison.