-->
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.  [ 4 posts ] 
Author Message
 Post subject: Check if record exists... Retrieve a single record...
PostPosted: Wed Jul 20, 2005 9:16 am 
How would I perform an ExecuteScalar() style function? I know it seems like a simple request, but I cant seem to find out how to do it anywhere.

Also, is there a way to simply check to see whether a record exists in the database? The only catch is I dont want to pass the ID identity column. I want to check to see if a record exists by checking a column that isnt the primary key.

For example, pass a string to check if a certain username exists, in a table where there is a column called ID that is the identity and primary key.

(In simple ado.net, I used an ExecuteScalar() and if it didnt return anything, I returned false, and if it did return a record, i returned true. fairly simple. jut wondering if there is a way to do this simply in nHibernate?)

Thanks!


Top
  
 
 Post subject:
PostPosted: Wed Jul 20, 2005 9:38 am 
Regular
Regular

Joined: Mon Jul 18, 2005 4:10 am
Posts: 92
Location: Poland
You need to take a look at the 'scalar queries' at the docs:
http://nhibernate.sourceforge.net/h2.0.3-docs/reference/html/manipulating-data.html#manipulating-data-s4

The first tip at 'tips&tricks' may apply also:
http://nhibernate.sourceforge.net/h2.0.3-docs/reference/html/query-language.html#query-language-s11

hth

_________________
michal


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 21, 2005 9:19 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Do
Code:
select count(*) from User u where u.Name = 'username'

or
Code:
select u.ID from User u where u.Name = 'username'

(to be able to directly use the ID to load the user :) )

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject: Thanks KPixel.
PostPosted: Thu Jul 21, 2005 12:41 pm 
Just one more question though. I put this into a session.Find()? or session.Query()?

Im a newbie at nhibernate...

Thanks for the help!


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