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: Criteria-Search and subquerry
PostPosted: Mon Mar 10, 2008 5:28 am 
Newbie

Joined: Tue Oct 30, 2007 10:53 am
Posts: 8
Location: Luxemburg
Hieverybody!

I've got a question about ICriteria and Subquerries.

I use

Code:
mCritSearch = session.CreateCriteria(typeof(TMaterial));
mCritProgramId = mCritSearch.CreateCriteria("ProgramId");

mCritSearch.Add(Expression.Eq("Name", inValue));
mCritProgramId.Add(Expression.Eq("Name", inValue));


which delivers me all the TMaterial Objects where the "Name" attribute of the TMaterial and the "Name" of the TProgram subclass equals my inValue. But instead of haeving an AND connection between these two, I would like to search for an OR to get all the results where at least one of the two "Name" meets my inValue.

Do you know how I could solve this? Thanks for any kind of help.

Best regards, Martin


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 10, 2008 6:56 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
I think this should work:

mCritSearch = session.CreateCriteria(typeof(TMaterial), "m")
.CreateCriteria("ProgramId", "p")
.Add(
Expression.Or(
Expression.Eq("m.Name", inValue),
Expression.Eq("p.Name", inValue)
)
);

_________________
--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.