views:

105

answers:

1

I define my data model using Fluent nHibernate POCO classes + mappings. I'm also using nHiberate schema to create database schema. All is working fine but there is one unpleasent fact. When I use many-to-one reference referece is named by something similair to GUID instead of any descriptive name. Here's a piece of SQL:

alter table [Odbiorca] 
        add constraint FK291D244B5D9E8115 
        foreign key (Adr_IdKraj) 
        references [Kraj]

I want nHiberate to generate something like Sql Studio does like [FK_Odbiorca_Kraj]. Is it doable by overridding mappings or by creating any convention?

+2  A: 

I don't know Fluent, but with regular XML mapping you just can use the foreign-key attribute:

<many-to-one 
  name="Kraj" 
  class="Kraj" 
  column="Adr_IdKraj" 
  foreign-key="FK_Odbiorca_Kraj"/>
Stefan Steinegger
FNH: `References(x => x.Kraj).ForeignKey("FK_Odbiorca_Kraj");`
James Gregory