tomo
tomo

Reputation: 1950

Fluent nHibernate - unfriendly many-to-one reference name

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?

Upvotes: 0

Views: 532

Answers (1)

Stefan Steinegger
Stefan Steinegger

Reputation: 64628

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"/>

Upvotes: 2

Related Questions