-->
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: how to make an Nhibernate.Expression notEqual expression?
PostPosted: Mon Dec 12, 2005 3:32 pm 
Newbie

Joined: Mon Dec 12, 2005 3:23 pm
Posts: 1
I am writing a piece of c# code which use Nhibernate to do a query. It require to do a not equal expression, I tried to use Nhibernate.Expression, but it dosen't work, please help! Thanks!

public static Deal_Model[] FindSearchDeal(string dealId,string dealName,string from,string to)
{

//get number of criterias
int count=0;
if(dealId!=null)
count++;
if(dealName!=null&&dealName!="")
count++;
if((from!=null&&from!="")||(to!=null&&to!=""))
count++;

int countObj=0;
if(count>0)
{
NHibernate.Expression.ICriterion[] expObj;
expObj =new NHibernate.Expression.ICriterion[count];
//how to make an not equal to expression?
/* if(dealId!=null&&dealId!="")
{
expObj[countObj]=Expression.NotEqual("Id", dealId); //that dosen't work
countObj++;
}*/


if(dealName!=null&&dealName!="")
{
expObj[countObj]=Expression.Eq("Name", dealName);
countObj++;
}

if(from!=null&&from!=""||to!=null&&to!="")
{
if(from!=null&&from!=""&&to!=null&&to!="")
{
expObj[countObj]=Expression.Between("Prospectus_date",from,to);
countObj++;
}
else
{
if(from!=null&&from!="")
expObj[countObj]=Expression.Eq("Prospectus_date",from);
else
expObj[countObj]=Expression.Eq("Prospectus_date",to);
}
}

return (Deal_Model[]) FindAll( typeof(Deal_Model),expObj);
}
else
{
return (Deal_Model[]) FindAll( typeof(Deal_Model),Expression.Eq("Historical", 0));
}



}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 13, 2005 4:45 am 
Regular
Regular

Joined: Fri Jun 11, 2004 6:27 am
Posts: 81
Location: Yaroslavl, Russia
Perhaps the following will help:
Code:
Expression.Not( Expression.Eq( "Id", dealId ) )

_________________
Best,
Andrew Mayorov // BYTE-force


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.