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: search on one to many properties
PostPosted: Tue Mar 03, 2009 4:54 am 
Beginner
Beginner

Joined: Fri Sep 26, 2008 9:19 am
Posts: 20
Location: Belgium
Hibernate version: 2.0

Hey guys,

I've built a simple class of which you can create a list of conditions to add to the criteria list of NHibernate to find a list by properties.
by this i'm also able to search on properties of many-to-one and one-to-one object properties
(for example select orders where Order.Customer.Name = "john")


example part:

Code:
                    case ObjectGetterConditionOperator.LessThanOrEqual:
                        crit.Add(Expression.Le(Projections.Property(cond.PropertyName), cond.PropertyValue));
                        break;
                    case ObjectGetterConditionOperator.Like:
                        crit.Add(Expression.Like(Projections.Property(cond.PropertyName), cond.PropertyValue));
                        break;


now i would like to create a part of this so i can also add criteria for one to many or many to many collections in an object.
(For example: select orders where Order.OrderItem.Product.Name = "fish")

My property would be an IList (<bag> in mapping)
Is this possible?

What Expression do i have to use to get a list of orders that have an orderitem that contains a specific product or even productname?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 03, 2009 11:23 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You have to create a sub criteria with either CreateCriteria or CreateAlias:

Code:
crti.CreateCriteria("BagPropertyName")
     .Add(Expression.Like(cond.PropertyName, cond.PropertyValue))

_________________
--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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.