Question

I'm trying to get a Tag Cloud architecture working in NHibernate.

public class Tag : Entity
{
    public virtual int Id { get; set; }
    public virtual string Text { get; set; }
}

This table will map to a few entities in my schema so I don't want to add a collection to the Tag class for each association.

I do however want to query the tag entities and return count(*) across all joined tables. I could do this easily in SQL but i'm not seeing the light with NH just yet.

Started off writing some HQL.

select t.Text, count(t.Id) 
from Tag t join ????
where t.Id= :tagid 
   group by t.Text

What do I join to? since in the object model the many-to-many bridge table has no class and no property, does this mean this can't work?

What would you suggest? Id be interested to see if this could be done in Criteria.

Many Thanks,

Ian

Was it helpful?

Solution

How about this as a start with using Criteria, I haven't run it and I don't know how to do the join...

 IList multiResults = s.CreateMultiCriteria()
     .Add(s.CreateCriteria(typeof(Tag)).SetProjection(Projections.RowCount()))
     .List();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top