if my ClassMap contains a Reference(m => m.Store).Column(“StoreId”) and I call SchemaExport, then my database table contains two foreign key columns, one named ‘StoreId’ and one named ‘Store_id’.
If I leave the Column() method, then its only gonna create the ‘Store_id’ column.
Is this a bug in the FluentNHibernate framework?
I’d like to have the ‘StoreId’ column only.
Thanks in advance.
public class EntityMap<T> : ClassMap<T> where T : Entity
{
public EntityMap()
{
Id( m => m.Id );
}
}
public class StoreMap : EntityMap<Store>
{
public StoreMap()
{
Map( m => m.Name );
HasMany( m => m.Staff )
.Inverse()
.Cascade.All();
HasManyToMany( m => m.Catalogue )
.Table( "Store_Product" )
.Cascade.All();
}
}
public class EmployeeMap : EntityMap<Employee>
{
public EmployeeMap()
{
Map( m => m.LastName );
Map( m => m.FirstName );
References( m => m.Store ).Column( "StoreId" );
}
}
public class ProductMap : EntityMap<Product>
{
public ProductMap()
{
Map( m => m.Name );
HasManyToMany( m => m.Stores )
.Table( "Store_Product" )
.Inverse()
.Cascade.All();
}
}
Found the solution now, though its not described anywhere I looked.
You have to set the column bidirectional. Then the “Store_id” column disappears. Thank you all for your answers!
For my above example: