I found a way to do it in HQL:
IQuery query = NHibernateHelper.GetCurrentSession()
.CreateQuery("from Square as s where s not in (select
s from Square as s left join s.Items as i where i.ItemId = :ItemId)");
query.SetParameter("ItemId", ItemId);
Is this a good solution? Would prefer Criteria API solution though.
C
On Jun 22, 12:45 pm, csetzkorn <[email protected]> wrote:
> I have a many-to-many relationship between two objects (Square and
> Item).
>
> I would like to obtain the selected and unselected squares for each
> item using criteria queries. This would be easy in SQL and I guess
> HQL.
>
> Getting the selected squares seems to work:
>
> public IList<Square> getSelectedSquares(long ItemId)
> {
> ICriteria crit = NHibernateHelper.GetCurrentSession
> ().CreateCriteria(typeof(Square))
> .CreateCriteria("Items")
> .Add(Expression.Eq("ItemId", ItemId));
>
> return crit.List<Square>();
> }
>
> But I struggle to get the unselected squares. Tried all kinds of
> things, for example:
>
> public IList<Square> getUnSelectedSquares(long ItemId)
> {
> ICriteria crit = NHibernateHelper.GetCurrentSession
> ().CreateCriteria(typeof(Square))
> .CreateCriteria("Items")
> .Add(Expression.Not((Expression.Eq("ItemId", ItemId))));
>
> return crit.List<Square>();
> }
>
> Looking forward to hearing from you.
>
> Best wishes,
>
> Christian
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---