簡體   English   中英

流利的NHibernate-如何使用GeneratedBy.Native()為Id指定序列名稱

[英]Fluent NHibernate - how to specify sequence name for Id with GeneratedBy.Native()

我使用Fluent NHibernate,並且需要使用GeneratedBy.Native()來生成ID以支持Oracle,DB2和MSSQL數據庫。 如果我嘗試在Oracle上像這樣運行它,並將新記錄插入到表中,則會得到:

Could not execute query: select hibernate_sequence.nextval from dual
System.Data.OracleClient.OracleException (0x80131938): ORA-02289: sequence does not exist

映射類:

public sealed class ListDataMap : ClassMap<ListData>
{
    public ListDataMap()
    {
        Table("LIST_DEF");

        Id(x => x.Id, "ID").Not.Nullable().GeneratedBy.Native();
        //other mapping
    }
}

如何指定序列名稱? 我不想使用hibernate_sequence,因為我需要多個序列,並且我不想擁有1個共享序列。

謝謝!

我在這里找到了答案: http : //thatextramile.be/blog/2007/07/native-id-generation-with-nhibernate/

就這么簡單:

Id(x => x.Id, "ID").Not.Nullable().GeneratedBy.Native(
    builder => builder.AddParam("sequence", "SEQ_LIST_DEF")
);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM