-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Querying IList using restrictions
PostPosted: Thu Aug 19, 2010 6:21 am 
Newbie

Joined: Wed Aug 18, 2010 9:46 am
Posts: 1
I have 2 classes:

Quote:
Class FruitShop
{
int FruitShopId;
string FruitShopName;
IList<Fruit> Fruits {ge;set;}
}

class Fruit
{
int FruitID {get; set;}
string FruitName {get; set;}
bool IsSweet {get; set;}
}


How can I write an expression to return from FruitShop Table, all records, that have a record existing in Fruits with Name "Mango"

I.e.

Return all FruitShop where FruitShop.Fruits.contains Any Fruit where Fruit.FruitName = "Mango"

How can I write an Nhibernate ICreterion for this and what should be the restriction ? something like

ICriteria criteria = CreateCriteria();
...
criteria.Add(restrictions.Eq(x=> x.Fruits.???, ???));


Quote:
As a note,
If I had to check for a FruitshopID 123, I would have written:
criteria.Add(restrictions.Eq(x=> x.FruitShopId, "123"));


Top
 Profile  
 
 Post subject: Re: Querying IList using restrictions
PostPosted: Wed Aug 25, 2010 3:57 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
ICriteria criterie = session.CreateCriteria(typeof(FruitShop),"x");
criteria.CreateCriteria("x.Fruits", "f").Add(Restrictions.Eq("f.FruitName","Mango").List<FruitShop>()

_________________
--Wolfgang


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.