you can use another special "injected" property TaggedItem.Item.class if you
want ask for a certain class.In practice in HQL or Criteria you have only
two available property for the <any> association:
TaggedItem.Item.id, TaggedItem.Item.class
Nothing more because NH can discover the type only loading a TaggedItem.
If you need to execute a query using a property of one of the associated
entities you can do what we talk above:

select ti from TaggedItem ti, Article a, Photo p where (ti.Item.id = a.Id or
ti.Item.id = p.Id) and ...... etc.

2009/1/10 ccollie <[email protected]>

>
> Fabio,
>  thanks, that covers the basics. But one further clarification. You're
> saying that there is no way to do a Type predicate check or projection
> on TaggedItem.Item
> using either Hql or ICriteria ? For example, to get all types tagged
> with a term if i dont know the type beforehand.
>
>
> On Jan 10, 1:49 pm, "Fabio Maulo" <[email protected]> wrote:
> > You can do it only using an "implicit join" between TaggedItem and one of
> > the <any> implementationselect a from TaggedItem ti, Article a where
> > ti.Item.id = a.Id
> >
> > Note the "ti.Item.id": the "id" property is a special "injected"
> property by
> > NH. Using "id" in lowercase NH use the POID of the related entity.
> >
> > 2009/1/10 ccollie <[email protected]>
> >
> >
> >
> >
> >
> > > Im writing a generic taxonomy/tagging module where any entity in the
> > > system can be tagged. The tagging table looks like
> >
> > > id  int
> > > UserId  int
> > > TaggedAt  Date
> > > Term             varchar
> > > ContentType  varchar
> > > ContentId   int
> >
> > > To make this implementation easier (since i dont impose a base class
> > > on the tagged entities), i want to use the Any type mapping:
> >
> > > <class  name='SocialDance.Core.Domain.TaggedItem,
> > > SocialDance.Core.Domain'  table='`TaggedItem`'>
> > >       <id name='Id'>
> > >              <generator class='identity'/>
> > >       </id>
> >
> > >        <many-to-one name="TaggedBy"
> class="SocialDance.Core.Domain.User,
> > > SocialDance.Core.Domain" column="userId" not-null="false" />
> >
> > >      <property name="Term" column="Term" type="String" length="50" />
> > >     <property name="TaggedAt" column="TaggedAt"/>
> >
> > >       <any name='Item' meta-type='System.String' id-
> > > type='System.Int32'>
> > >              <meta-value class='SocialDance.Core.Domain.Article,
> > > SocialDance.Core.Domain' value='ARTICLE'/>
> > >              <meta-value class='SocialDance.Core.Domain.Photo,
> > > SocialDance.Core.Domain' value='PHOTO'/>
> > >              <meta-value class='SocialDance.Core.Domain.BlogPost,
> > > SocialDance.Core.Domain' value='POST'/>
> > >              <column name='ContentType'/>
> > >              <column name='ContentId'/>
> > >       </any>
> >
> > > </class>
> >
> > > My question is how do i query on the Any association ? I looked at
> > > NHibernate's tests for the any mapping and they offer no clues. In
> > > particular, i need to query for the tags on a particular item (seems
> > > ok), and particular types (e.g. all photo tags for tag cloud calcs). I
> > > assume that i cant query on any properties of TaggedItem.Item beyond
> > > its type and id.
> >
> > > Thanks
> >
> > --
> > Fabio Maulo
> >
>


-- 
Fabio Maulo

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to