如何正确使用 Fluent NHibernate 在 Oracle 中获取下一个 Sequence?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4097784/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 21:50:53  来源:igfitidea点击:

How to properly use Fluent NHibernate to get the next Sequence in Oracle?

oraclenhibernatefluent-nhibernate

提问by Chris Martindale

I'm using NHibernate / Fluent NHibernate with Oracle and I'm running into an issue. I've got the following mapping file defined:

我在 Oracle 中使用 NHibernate / Fluent NHibernate,但遇到了一个问题。我已经定义了以下映射文件:

public OrderMap()
{
    Table("ORDERS");
    Id(x => x.OrderId, "ORDER_ID").GeneratedBy.Sequence("select ORDERS_SQ.nextval from orders");
    Map(x => x.CreatedBy, "CREATED_BY");
    Map(x => x.OrderStatusCd, "ORDER_STATUS_CD");
    Map(x => x.StoreGroupId, "STORE_GROUP_ID");
    Map(x => x.IsActive, "IS_ACTIVE");
    Map(x => x.OrderDate, "ORDER_DATE");
}

When I go to run my project I get the following error:

当我去运行我的项目时,我收到以下错误:

An invalid or incomplete configuration was used while creating a SessionFactory.

创建 SessionFactory 时使用了无效或不完整的配置。

If I remove the .GeneratedBy.Sequence("select ORDERS_SQ.nextval from orders");line, the application runs but I don't get the next sequence obviously when I save a record. I've tried doing just .GeneratedBy.Sequence("ORDERS_SQ");but I just don't seem to get anything to work right.

如果我删除该.GeneratedBy.Sequence("select ORDERS_SQ.nextval from orders");行,应用程序将运行,但当我保存记录时,显然不会得到下一个序列。我试过做,.GeneratedBy.Sequence("ORDERS_SQ");但我似乎没有任何事情可以正常工作。

Can anyone tell me the proper way to use Fluent NHibernate to get the next available sequence correctly please?

谁能告诉我使用 Fluent NHibernate 正确获取下一个可用序列的正确方法吗?

I'm using Fluent NHibernate 1.1 with NHibernate 3.0 Beta.

我正在使用 Fluent NHibernate 1.1 和 NHibernate 3.0 Beta。

Thanks.

谢谢。

回答by rebelliard

Just specify the name of the sequence:

只需指定序列的名称:

Id(x => x.OrderId).Column("ORDER_ID").GeneratedBy.Sequence("ORDERS_SQ");

// Real working code:
Id(x => x.Id).GeneratedBy.Sequence("SEQ_Catalog1");