1

通过流利的 nhibernate,我不能使用带有约定的自动映射,因为它为关系表添加了额外的外键。该问题已在stackoverflow.com/questions/6091654/fluentnhibernate-automapping-onetomany-relation-using-attribute-and-convention/7867516详细解释

但是正如你所看到的,它是通过使用属性来解决的。我的问题是:

我不想在 Model Properties 上使用属性。因为在接下来的几年里,我们可能不会在项目中使用 nhibernate。所以我不想碰模特。没有 KeyColumnAttribute 的问题是否有解决方案。

谢谢

4

1 回答 1

0
class BiDirectionalHasManyConvention : IReferenceConvention, IHasManyConvention
{
    public void Apply(IOneToManyCollectionInstance instance)
    {
        // looks for a Property which references the type containing the collection
        var referenceProperty = instance.ChildType.GetProperties()
            .First(prop => prop.PropertyType == instance.EntityType);

        instance.Key.Column(referenceProperty.Name + "Id");
    }

    // Optional, just to make sure the foreignkey column is propertyname + "Id"
    public void Apply(IManyToOneInstance instance)
    {
        instance.Column(instance.Name + "Id");
    }
}
于 2011-12-08T08:22:55.363 回答