Fluent Nhibernate 1.0 - 指定类和连接子类之间的外键约束名称
我认为这应该很简单,但我不知道该怎么做。假设我有以下映射:
public class AnimalMap : ClassMap<Animal> { Id( x => x.Id); }
public class CatMap: SubclassMap<Cat> {
Extends<AnimalMap>();
Map(x => x.IsDomestic);
}
它按照我的预期创建表:
Animal
------
Id
Cat
----
AnimalId : FK to Animal (named FK3500ABA0D)
IsDomestic
如前所述,FK 由数据库生成,最终为 FK3500ABA0D。我想做的就是设置该约束的名称,但我找不到如何通过 Fluent NHibernate(或者实际上是普通的 NHibernate)来完成它。
那么,我错过了什么?
I think this should be simple, but I can't figure out how to do it. Suppose I have the following maps:
public class AnimalMap : ClassMap<Animal> { Id( x => x.Id); }
public class CatMap: SubclassMap<Cat> {
Extends<AnimalMap>();
Map(x => x.IsDomestic);
}
Which creates tables as I expect:
Animal
------
Id
Cat
----
AnimalId : FK to Animal (named FK3500ABA0D)
IsDomestic
As noted, the FK gets generated by the db and ends up as FK3500ABA0D. All I want to do is set the name of that constraint, but I can't find how to do it via Fluent NHibernate (or actually even plain NHibernate, for that matter).
So, what am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Fluent NH 确实允许这样做:
您还需要以与上述相同的方式实现
IHasManyConvention
和IHasManyToManyConvention
。Fluent NH does allow this:
You'd also need to implement
IHasManyConvention
andIHasManyToManyConvention
in the same way as above.我不知道 FluentNH 是否支持,但是 XML 很简单:
I don't know if FluentNH supports it, but the XML is simple:
我遇到了同样的问题,以下内容对我来说效果很好:
然后您的外键约束将被命名为 FK_Cat_Animal
I had the same problem, the following works well for me:
Your foreign key constraint would then be named as FK_Cat_Animal