Search code examples
fluent-nhibernateautomapping

How do I turn off Identifiergeneration in fluent nhibernate when using automapping


I use NHibernate 3.0 with fluent configuration. I automap my persistent model like this:

AutoMap
    .AssemblyOf<BaseEntity>()
    .Where(type => type.Namespace != null && type.Namespace.Contains("PersistendModel"))

This works fine, but I don't want to use the default identifierGenerators. My objects have initialized GUID Id's, but as it stands now they are overwritten by NHibernate.

What do i need to add (Convention, Override, SomeThingElse?), so this will not happen.


Solution

  • I added the following convention:

    public class IdConvention : IIdConvention
    {
    
        public void Apply(IIdentityInstance instance)
        {
            instance.GeneratedBy.Assigned();
        }
    
    }
    

    this does the trick for all my persisted classes in one go.