4

I have an entity mapping quite similar to this one.

public class MyClassMap : ClassMap<MyClass>
{
    public MyClassMap()
    {
        Id(x => x.Id);
        Map(x => x.Code);

        Map(x => x.Name);
        Map(x => x.Description);
    }
}

I'd like to know if there's any possible way to have the Code field (which is not part of the Primary Key) autogenerated by a sequence. There's a GeneratedBy property, but it's only an IdentityPart class member.

Mauro2
  • 1,235
  • 1
  • 7
  • 9

2 Answers2

1

I don't see how using Listeners makes it any easier to use a built-in method for using sequence generators for non-ID columns.

However, if the only solution is to hook into OnPreInsert, making a direct query to the DB & invoke the sequence and get its value, then I suppose I'll have to live with it.

Is this how you solved the issue, Mauro?

Edit: posted the question on the nHibernate & FluentNHibernate google groups: https://groups.google.com/group/nhusers/browse_thread/thread/35d37b9abf3566f0
https://groups.google.com/group/fluent-nhibernate/browse_thread/thread/35d37b9abf3566f0

agf
  • 171,228
  • 44
  • 289
  • 238
JoeBrockhaus
  • 2,745
  • 2
  • 40
  • 64
0

You need to use SaveOrUpdateEventListeners. See here to see Jake's reply for how to get it working for Fluent.

Community
  • 1
  • 1
Yogesh
  • 14,498
  • 6
  • 44
  • 69