views:

145

answers:

2

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.

+1  A: 

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.
}
Simon G
+4  A: 

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.

Lachlan Roche
Not really what we are looking for. We are trying to still automap the assembly. We don't want to create a manual mapping for the class only specify a different table name for one specific entity.
Matt
@Matt the second example uses automap and only changes the table name for a single entity
Lachlan Roche
@Lachlan yep that is what I was looking for found it about a minute before you posted it too. Thanks for the help
Matt