如何通过NHibernate从oracle序列获取NextVal [英] How do I get the NextVal from an oracle Sequence thru NHibernate

查看:109
本文介绍了如何通过NHibernate从oracle序列获取NextVal的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用c#.net 4.0,并使用NHibernate与Oracle DB进行通信.您会认为一些简单的事情已经解决了,但遗憾的是没有解决.我需要Oracle序列中的NextVal.我不需要将其作为ID或主键的一部分插入数据库.我只需要在c#端使用下一个val.

有人可以通过xml映射和C#文件(或链接)帮助我实现这一目标.

谢谢.



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 />
  }

推荐答案

尝试类似的方法:

Try something like this:

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



我没有方便的Oracle数据库来进行测试,但这至少应该可以使您走上正确的道路.



I don''t have an Oracle db handy to test it out, but this should at least get you on the right track.


这里是使用Oracle序列的紧肤方法. Oracle序列有两个可用功能.一个是NEXTVAL,另一个是CURRVAL. NEXTVAL将触发序列并将该值返回给您. CURRVAL获取您的最后一个退货.因此,重要的是在至少调用一次NEXTVAL之前不要调用CURRVAL.
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;


不过很抱歉,NHiberbate的产品我帮不上忙. :)


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


这篇关于如何通过NHibernate从oracle序列获取NextVal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆