My automapping:
return Fluently.Configure()
.Database(config)
.Mappings(m =>
m.AutoMappings.Add(
AutoMap.AssemblyOf<Company>()
.Where(
t => t.Namespace == "DAL.DomainModel" && t.IsClass)
.IgnoreBase<ReferenceEntity>()))
.BuildSessionFactory();
So ReferenceEntity is an abstract class containing a string Name, and all my reference entities inherit from this class. I'd like to modify my automapping to add a unique constraint to the Name field for all entities that inherit from ReferenceEntity.
I've gathered it has something to do with .Setup but I'm a bit lost on how to proceed.
note: I'm using the Fluent NHibernate v1.0 RTM so conventions will be with the new style if that is relavent to my goal.
Best Answer
If all your entities inherit from ReferenceEntity, wouldn't you want to create the unique constraint for the
Name
property on all the entities that are mapped?But if you want to filter by entity base class, you can do it. Use a convention to add the unique constraint to your mappings:
To get the convention (and all other conventions in the assembly) picked up by FNH, just add this line the
AutoMap
setup you have above:Alex,
No the answer doesn't change. Here is an example, using the convention above.
This creates sql of:
As long as these are separate entities, it will create a unique constraint on the .Name property for each entity.