代码之家  ›  专栏  ›  技术社区  ›  Matt

Fluent:表名与实体名不同

  •  3
  • Matt  · 技术社区  · 14 年前

    我尝试使用fluent with nhinbernate的自动应用功能来映射一个与表本身的名称不同的类。

    (这纯粹是出于风格原因,我们有一个名为foo的类,它包含一个名为bar的对象,但表名是foobar。我们不希望拥有foo.foobar属性。)

    我找不到任何细节来详细说明如何给Fluent这个变化的线索。

    2 回复  |  直到 14 年前
        1
  •  7
  •   Lachlan Roche    14 年前

    使用classmap,可以在 mapping .

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

    使用automap,可以覆盖表名。

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

    您也可以使用 conventions 影响所有实体的表命名。

        2
  •  2
  •   lancscoder    14 年前

    可以在映射中指定表名。所以看起来是这样的:

    public class FooMap : ClassMap<Foo>
    {
      Table("FooBar");
    
      // Rest of your mapping goes here.
    }