query to select orphans item

13 views
Skip to first unread message

kor

unread,
May 21, 2013, 5:13:53 AM5/21/13
to nhu...@googlegroups.com
hi, i have a "parent" entity that reference a list of items

<class name=Group>
<list name="Items" cascade="none">
      <key column="Group_Id" foreign-key="fk_ItemToGroupId"/>
      <index column="Item_Index"/>
      <one-to-many class="Item"/>
    </list>
</class>

<class name=Item>
</class>

i need to do a query (it's better if it's not hql but with queryover, query, etc) to select all the items not associated with a group.

the generated raw sql query that i want it's something similar to

select *
from Item i
where i.Group_Id is null

thanks

Pete Appleton

unread,
May 21, 2013, 5:22:51 AM5/21/13
to nhu...@googlegroups.com

Have you mapped Item.Group?  If so, then a simple

                session.QueryOver<Item>().Where(x => x.Group == null)

 

should do the trick.  If you haven't [which I suspect from the lack of "inverse" on the list], then NHibernate has no way of knowing how to formulate the question to the DB - you might want to consider using a bidirectional mapping

 

/Pete

--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+u...@googlegroups.com.
To post to this group, send email to nhu...@googlegroups.com.
Visit this group at http://groups.google.com/group/nhusers?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

kor

unread,
May 22, 2013, 8:24:46 AM5/22/13
to nhu...@googlegroups.com
thanks, i cannot use bidircetional becosue is not supported with list, i will do a raw sql query.

Ricardo Peres

unread,
May 22, 2013, 9:24:41 AM5/22/13
to nhu...@googlegroups.com
List supports bidirectional associations, you can (and should) use inverse.
Reply all
Reply to author
Forward
0 new messages