views:

36

answers:

0

Imagine the following tables :

Tag (TagId, Label)

Post (PostId, Title, Content)

User (UserId, Name)

UserPostTag (Id, UserId, PostId, TagId)

For a Post, multiple users can add one or more Tag.

I want to get, via nHibernate, the tag list for a post, with the count of each Tag.

Exemple or result :

Tag(id1, label1), 7

Tag(id2, label2), 5

Tag(id3, label3), 2

I know how to get list of tags for a post :

IList<Tag> tagList = session.CreateCriteria<Tag>()
 .Add(Subqueries.PropertyIn("TagId",
     DetachedCriteria.For<UserPostTag>()
         .Add(Restrictions.Eq("Post.PostId", 17))
         .SetProjection(Projections.Property("Tag.TagId"))
     ))
     .List<Tag>(); 

Can you please help me ?

Thanks a lot !

Sorry for my english ...

Sincerely,

Antoine