Click here to Skip to main content
15,903,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am working on c# .net 4.0 and using NHibernate to talk with an Oracle DB. You would think something as simple as this is already addressed somewhere but sadly its not. I need the NextVal from an Oracle sequence. I do not need to insert it a database as part of an Id or Primary key. I just need to use the next val on the c# side.

Can somebody help me out with xml mapping and C# file(or a link) to achieve this.

Thanks.

Something like

int NextValueOfSequence = GetNextValueofSequence(); <br />
<br />
 public int GetNextValueOfSequence() { <br />
 // Access NHibernate to return the next value of the sequence.<br />
  }
Posted

Try something like this:

<your session variable>.CreateSQLQuery("select <your sequence>.NEXTVAL from dual").UniqueResult<Int64>();


I don't have an Oracle db handy to test it out, but this should at least get you on the right track.
 
Share this answer
 
v2
Comments
trainer42in 7-Jan-11 17:07pm    
Thanks, That helped.
Here's the skinny on using an Oracle sequence. There are two functions available for an Oracle sequence. One is NEXTVAL and the other is CURRVAL. NEXTVAL will trigger the sequence and return that value to you. CURRVAL get's you the last one returned. Therefore it is important to not call CURRVAL until NEXTVAL has been called at least once.
select sequence.NEXTVAL from dual;
  or
select sequence.CURRVAL from dual;

Sorry though, I can't help you with the NHiberbate stuff. :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900