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.
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.
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.
}
精彩评论