简体   繁体   English

流畅的NHibernate与合成键一对一映射

[英]Fluent NHibernate one-to-one mapping with synthetic keys

I have two tables 我有两张桌子

tblPart
(
    partId,
    subpartId UNIQUE NULL
)

tblSubpart
(
    subpartId
)

So I can only have zero or one subPart associated with the part at the same time. 因此,我只能同时具有零个或一个与该零件关联的子零件。

I'm trying to map this as 我正在尝试将此映射为

ClassMap<Part>
{
    HasOne(x=>x.Subpart);
}

and the convention rewrites the foreign key so it uses subpartId instead of partId. 并且约定重写了外键,因此它使用subpartId而不是partId。

however generated query ads 但是生成的查询广告

subpart.partId

into the query, which does not exist. 进入查询,该查询不存在。

What am I doing wrong here? 我在这里做错了什么?

Why not use inheritance? 为什么不使用继承?

Check out this question 看看这个问题

Inheritance Mapping with Fluent NHibernate 使用Fluent NHibernate进行继承映射

And this page (search inheritance to jump to the right section) 和此页面(搜索继承跳转到右侧部分)

http://wiki.fluentnhibernate.org/Fluent_mapping http://wiki.fluentnhibernate.org/Fluent_mapping

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM