Fluent: table name other than object name

I am trying to use the Fluent autopilot function with nHinbernate to map a class to a different name than the table itself is a name.

(For purely stylistic reasons, we have a class called Foo that contains an object called Bar, but the table name is FooBar. We probably won't have the Foo.FooBar property.)

I cannot find anything more detailed than giving Fluent the key to this change.

+3
source share
2 answers

With classmap you can specify the table name in mapping .

public class BarMap : ClassMap<Bar>
{
    public BarMap()
    {
        Table("FooBar");
    }
}

With automap, you can override the table name.

.Mappings( m => m.AutoMappings.Add( AutoMap.AssemblyOf<Bar>()
    .Override<Bar>( b => {
        b.Table("FooBar");
}))

conventions, .

+7

. :

public class FooMap : ClassMap<Foo>
{
  Table("FooBar");

  // Rest of your mapping goes here.
}
+2

Source: https://habr.com/ru/post/1738505/


All Articles