Search code examples
fluent-nhibernateindexingautomapping

Add (unique)index to properties of Fluent Nhibernate auto mapped classes


We are using Fluent NHibernate with automapping for our objects. Something like:

AutoPersistenceModel autoMap =
    AutoMap
    .Assemblies(mappingConfig, assembliesToMap.ToArray())
    .Conventions.AddFromAssemblyOf<BaseEntity>();   

I want to to add some indexes to some properties of my objects

I suspect that it can be done somewhere in the mappingConfig object, but I have no idea how this should be done!

Ideas anyone?


Solution

  • You may need to use overrides to do this:

    http://wiki.fluentnhibernate.org/Auto_mapping#Altering_entities

    .Override<Shelf>(map =>
    {
      map.Map(x => x.SomeProperty)
         .Index("ix_myIndex");
    });