views:

186

answers:

1

Hi,

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

+1  A: 

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();
Chris Missal
Its quite frustrating when the sql is so simple. For example if i have tag and entity joined by entity_tag table. All I need for a count of tags isSelect t.Text, count(*) From Tag t Join Entity_Tags eton et.TagId = t.IdGroup by t.textI'm not sure I can get something so concise out of NH. I really do not want to pollute my tag model class with collections just to get NH to work.
madcapnmckay