I think there are several ways to do what you are trying to do.
The first is to specify a name in the mapping file. I know this works for foreign keys, although I have not tried with unique keys.
<property name="KeyId" column="KeyId" type="Int" unique="true" unique-key="MyKeyName"/>
Inside NHibernate, you can change the naming strategy by creating a class that implements NHibernate.Cfg.INamingStrategyand adds this class when you configure nhibernate.
ISessionFactory sf = new Configuration()
.SetNamingStrategy(new YourNamingStrategy())
.Configure()
.SchemaExport(true, false);
ImprovedNamingStrategy, nhibernate. , , .
ISessionFactory sf = new Configuration()
.SetNamingStrategy(ImprovedNamingStrategy.Instance)
.Configure()
.SchemaExport(true, false);
,
. , , .
<property name=KeyID>
<column name="KeyId" unique-key="MyKeyName"/>
</property>
-
-
<database-object >
<create>
create table MyTable(
Id UNIQUEIDENTIFIER not null,
Name NVARCHAR(10) not null,
RowVersion INT not null,
primary key (Id)
)
ALTER TABLE dbo.MyTable ADD
CONSTRAINT IX_Table_1 UNIQUE NONCLUSTERED(Name)
WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
</create>
<drop></drop>
</database-object>
, NHibernate.Mapping.IAuxiliaryDatabaseObject, DDL.
NHiberate nhibernate.info
5,6.
, .