Search code examples
fluent-nhibernateautomapping

Overriding Fluent NHibernate Automappings


This is a Fluent NHibernate newbie question, so bear with me.

I have a set of classes, and I'm applying the Automapping capabilities to it.

But I need to mark one of the properties of one of the techniques with a Unique constraint.

In the Fluent Wiki, it says

Sometimes it's necessary to make slight changes to a specific entity, without wishing to affect anything else; you can do that with the with Override method.

.Override(map => {
map.HasMany(x => x.Products) .Cascade.All(); });

But I can't figure out what object to apply the .Override method to.

Right now, I have

AutoPersistenceModel returnModel = AutoMap.AssemblyOf()

But the AutoPersistenceModel object does not have an Override method.

Can someone give me some simple sample code to walk me through this, or point me to some links with some examples?

Thanks.


Solution

  • It does have an Override method in the 1.0 RTM. You use it like this:

    AutoMap.AssemblyOf<Person>().Override<Shelf>(map =>
    {
        map.HasMany(x => x.Products).Cascade.All();
    });