Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I think that there is a couple of ways to do what you are trying to to.</p> <p>The first one is to specify the name in the mapping file. I know it works for foreign keys, though I haven't tried with unique keys. </p> <pre><code>&lt;property name="KeyId" column="KeyId" type="Int" unique="true" unique-key="MyKeyName"/&gt; </code></pre> <p>Within NHibernate you can change the Naming Strategy by creating a class that implements <code>NHibernate.Cfg.INamingStrategy</code> and adding that class when you configure nhibernate.</p> <pre><code>ISessionFactory sf = new Configuration() .SetNamingStrategy(new YourNamingStrategy()) .Configure() .SchemaExport(true, false); </code></pre> <p>The is also an ImprovedNamingStrategy that is built in to nhibernate. Can't remember what it outputs off hand but worth a try</p> <pre><code>ISessionFactory sf = new Configuration() .SetNamingStrategy(ImprovedNamingStrategy.Instance) .Configure() .SchemaExport(true, false); </code></pre> <p><strong>EDIT</strong><br> There are a couple of other possibilities I have found the first one involves the property tag. there is a column tag that has a number of attributes that may be of use.</p> <pre><code>&lt;property name=KeyID&gt; &lt;column name="KeyId" unique-key="MyKeyName"/&gt; &lt;/property&gt; </code></pre> <p>the other one is a bit more involved You can either add something like this </p> <pre><code>&lt;database-object &gt; &lt;create&gt; 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] &lt;/create&gt; &lt;drop&gt;&lt;/drop&gt; &lt;/database-object&gt; </code></pre> <p>Or create a class that implements <code>NHibernate.Mapping.IAuxiliaryDatabaseObject</code> which will create the DDL statements.<br> Have a look in the <a href="http://nhibernate.info/doc/nhibernate-reference/mapping.html#mapping-database-object" rel="nofollow noreferrer">NHiberate manual on nhibernate.info</a> and scroll down to </p> <blockquote> <p>5.6. Auxiliary Database Objects</p> </blockquote> <p>This explains what you need to do.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload