Search code examples
oracle-databasenhibernatefluent-nhibernateidentity

NHibernate mapping GeneratedBy.SequenceIdentity("seq") where PK is a string


I am trying to map a PK in an Oracle table with Fluent NHibernate. The PK is a string (the database schema cannot be changed). The PK is generted by a Sequence. This is a legacy database, there is no trigger on the table, only the sequence.

With Fluent NHibernate, I am trying

this.Id(x => x.Id)
    .Column("FOO_ID")
    .Not.Nullable()
    .GeneratedBy
    .SequenceIdentity("SEQ");

but am receiving

Identity type must be integral (int, long, uint, ulong)

because SequenceIdentity() checks that the value is an integral.

How do I achieve this with a string PK? The same approach with a integral id works.


Solution

  • I didn't know that Oracle supports string sequences. But anyway, I don't believe that NHibernate supports string sequences out of the box.

    However you can create your own ID generators in NHibernate.

    You will probably find that you need something similar to the inbuilt SequenceGenerator class, so I would start with that code and see what you can come up with.