sni*_*ker 4 c# nhibernate fluent-nhibernate
目前我正在使用Fluent NHibernate生成我的数据库模式,但我希望HasMany关系中的实体指向不同的列以供参考.IE,这就是NHibernate在创建DDL时会生成的:
alter table `Pony` add index (Stable_ID),
add constraint Ponies_Stable foreign key (Stable_Id)
references `Stable` (Id);
Run Code Online (Sandbox Code Playgroud)
这就是我想要的:
alter table `Pony` add index (Stable_ID),
add constraint Ponies_Stable foreign key (Stable_Id)
references `Stable` (EntityId);
Run Code Online (Sandbox Code Playgroud)
其中Stable.ID是主键,Stable.EntityId只是我设置的另一列.
我已经有一个类看起来像这样:
public class ForeignKeyReferenceConvention : IHasManyConvention
{
public void Apply(IOneToManyCollectionInstance instance)
{
instance.Cascade.All();
//What goes here so that I can change the reference column?
}
}
Run Code Online (Sandbox Code Playgroud)
作为一个例子,这里是IReferenceConvention的代码看起来像做同样的事情:
public class MyReferenceConvention : IReferenceConvention
{
public void Apply(IManyToOneInstance instance)
{
instance.PropertyRef("EntityId");
instance.Cascade.All();
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:
instance.Key.Column("EntityId")
不是解决方案.
注意:这仅适用于Fluent NHibernate下载#632之后的版本
IOneToManyInstance
该被调用的属性Key
允许您修改关系中使用的密钥; 在那个属性上,有一种PropertyRef
方法,应该是你正在寻找的方法.
public class ForeignKeyReferenceConvention : IHasManyConvention
{
public void Apply(IOneToManyCollectionInstance instance)
{
instance.Key.PropertyRef("EntityId");
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1951 次 |
最近记录: |