2010-08-20 60 views
0

我正在尝试Fluent NHibernate中的子类映射。在FluentNHibernate中使用SubClass时,如何在子类表中指定PK的名称?

在父类映射,我必须指定ID列名,以防止FNH猜测不正确:

Id(x => x.Id).Column("UserId"); 

我还需要指定的ID(或外键,如果你喜欢)中字段名称子类映射,因为FNH也猜错了。我怎么做?

+1

这是世界上唯一一个在Fluent NHibernate中使用子类的孤独者。 :( – David 2010-08-23 08:05:09

回答

0

我还没有找到一种方法来直接修改映射文件本身,但我发现,覆盖流利NHibernate的外键约定的伎俩:

public class FKConvention : ForeignKeyConvention 
{ 
    protected override string GetKeyName(FluentNHibernate.Member property, Type type) 
    { 
    if (property == null) 
    { 
     // Relationship is many-to-many, one-to-many or join. 
     if (type == null) 
     throw new ArgumentNullException("type"); 
     return type.Name + "Id"; 
    } 
    // Relationship is many-to-one. 
    return property.Name + "Id"; 
    } 
} 

新的公约有作为解释登记在这个页面的底部:http://wiki.fluentnhibernate.org/Conventions

相关问题