-->
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.  [ 5 posts ] 
Author Message
 Post subject: Are These Expressions Equal?
PostPosted: Thu Aug 20, 2009 10:51 am 
Newbie

Joined: Thu Aug 20, 2009 10:03 am
Posts: 3
Hello there,
with the following Code i am trying to build a Criteria Query that should get me all the fitting attachmentHead Objects. Raw SQL should look Like this:

Code:
Select * from attachmentHeads Where maMailid = [arraycontent]


In my Project i tried something like this:
Code:
public IList getAttachmentHeads(IList mailsheads)
{
            ICriteria crit = session.CreateCriteria(typeof(attachmentHead));
            for (int i = 0; i < mailsheads.Count; i++ )
            {
                crit = crit.Add(Expression.Eq("maMailid", ((mailsHead)mailsheads[i].maMailid)));
            }
           return crit.List();
}


Instead of working properly it only returns an empty List.
What should I do?

Thx!


Top
 Profile  
 
 Post subject: Re: Are These Expressions Equal?
PostPosted: Fri Aug 21, 2009 2:01 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
crit = crit.Add(Expression.Eq("maMailid", ((mailsHead)mailsheads[i].maMailid)));

This statement creates "and". You have to either use Expression.Or(...) or Expression.PropertyIn(...):

Code:
ICriteria crit = session.CreateCriteria(typeof(attachmentHead));
List<int> ids = new Listt<int>(mailsheads.Count);
for (int i = 0; i < mailsheads.Count; i++ )
     ids.Add(((mailsHead)mailsheads[i].maMailid)));

return crit.Add(Expression.In("maMailid", ids ).List();

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Are These Expressions Equal?
PostPosted: Fri Aug 21, 2009 3:12 am 
Newbie

Joined: Thu Aug 20, 2009 10:03 am
Posts: 3
Danke ;)


Top
 Profile  
 
 Post subject: Re: Are These Expressions Equal?
PostPosted: Fri Aug 21, 2009 4:35 am 
Newbie

Joined: Thu Aug 20, 2009 10:03 am
Posts: 3
I still have a second question, wich is too minimal to have an own Thread:
How do i downscale the result to one Column/Property?

Have a nice day ;)


Last edited by TechJack on Fri Aug 21, 2009 4:38 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Are These Expressions Equal?
PostPosted: Fri Aug 21, 2009 4:38 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
criteria.SetProjection(Projections.Property("...."))

_________________
--Wolfgang


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.