开发者

Using NHibernate, how can I retrieve a list of composite-element objects given a parent's ID?

I presume this is an elementary question, but can't seem to find the answer. Using NHibernate, given a mapping with a one-to-many composite-element:

<class name="Event">
  <id name="Id">
    <generator class="guid" />
  </id>
  <set name="Items">
    <key column="EventId" />
    <composite-element class="EventItem">
        <property na开发者_StackOverflowme="SomeProperty">
    </composite-element>
  </set>
 </class>

How can I return an IList of just the child Items given a parent ID? I'd love to see an example in both HQL and criteria. My feeble and unsuccessful attempt:

session.CreateQuery("FROM Event.Items WHERE Event.Id = :id")
   .SetParameter("id", eventId)
   .List<EventItem>();


After several hours of looking, naturally I found the answer as soon as I posted.

session.CreateQuery("SELECT elements(e.Items) FROM Event e WHERE e.Id = :id")
   .SetParameter("id", eventId)
   .List<EventItem>();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜