问题描述
我正在使用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 />
}
推荐答案
<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.
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!