Matt
Matt

Reputation: 2815

Fluent: Table name different from entity name

I am trying to use the automapping feature of Fluent with nHinbernate to map a class with a different name than the table itself is name.

(This is purely for stylistic reasons we have a class named Foo which contains an object named Bar but the table name is FooBar. We would rather not have a property Foo.FooBar.)

I can't find anything detailing how to give Fluent a clue on this change.

Upvotes: 3

Views: 1239

Answers (2)

Lachlan Roche
Lachlan Roche

Reputation: 25946

With classmap you can specify the table name in the 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");
}))

You can also use conventions to affect table naming of all entities.

Upvotes: 7

lancscoder
lancscoder

Reputation: 8768

You can specify the table name in the mapping. So it will look something like this:

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

  // Rest of your mapping goes here.
}

Upvotes: 2

Related Questions