Control the name of the Primary Key and Unique Constraint Names
I'm looking for a way to control how the name of the primary key and unique key constraints are name. Not the properties/columns, but the name of the actual key. I'm using the export option of NH to regenerate my database for my unit tests, but the key names in question are always different. I'd like to be able to use schema comparisson tools to look at changes between what I'm currently working on and what is currently in production, and the key names changing all the time makes it hard.
Here is an example of a unique key name: UQDepartme737584F646F66FB7. The last part of the name is the part that always changes. I'd like to be able to create a convention so that I can specify something like UQ_TableName_ColumnName, but I'm not having any luck in figuring out which convention to use, or if this is even possible.
Thanks
Adam
Support Staff 2 Posted by Paul Batum on 21 Aug, 2010 02:53 PM
To the best of my knowledge, NHibernate doesn't support this so we have no
way to support it in Fluent NH.
On Sat, Aug 21, 2010 at 5:01 AM, Adam <
***@tenderapp.com<tender%***@tenderapp.com>
> wrote:
Support Staff 3 Posted by James Gregory on 21 Aug, 2010 05:26 PM
You can specify the unique key name using UniqueKey, but Paul's right about
the primary key name; that's a limitation of NHibernate, and until they fix
it we can't do anything about it. I don't think they will be fixing it
either, last I heard it was some deep architectural issue.
On Sat, Aug 21, 2010 at 3:55 PM, Paul Batum <
***@tenderapp.com<tender%***@tenderapp.com>
> wrote:
Support Staff 4 Posted by Paul Batum on 22 Aug, 2010 01:23 AM
Ahh didn't know that unique keys were possible. Thanks for the correction
James.
On Sun, Aug 22, 2010 at 3:28 AM, James Gregory <
***@tenderapp.com<tender%***@tenderapp.com>
> wrote:
5 Posted by Dave on 03 Sep, 2010 05:09 PM
Just to clarify...
Foreign keys can be given custom names from one of the following methods:
The code about would convert random key constraint names into explicit constraint names, for example:
FK3903425823405 turns into FK_TableName_ColumnName.
Is this thread stating that there is no similar mechanism in place to convert:
PK5349058340093485, to
PK_TableName
Sorry for being verbose and/or redundant, but confirmation on this would save a few hours of Google-ing.
Support Staff 6 Posted by James Gregory on 03 Sep, 2010 05:25 PM
Correct.
Foreign key constraint names are customisable. Primary key constraint names are not.
This is an NHibernate limitation, not a Fluent NHibernate.
7 Posted by PrzemasG on 07 Sep, 2010 06:27 PM
James, Adam was talking about UNIQUE keys, not FOREIGN keys...
As I know, Fluen doesn't allow to name unique keys, am I right?
8 Posted by dario-g on 18 Nov, 2010 03:32 PM
EntityType is always null (FNH 1.1) :(