[英]NHibernate - Composite-Id on relation - Where ID of parent is not same composite
Say I have these table in an Oracle database 说我在Oracle数据库中有这些表
Person: 人:
PersonId <- PK ID (int, from sequence) PersonId <-PK ID(int,从序列开始)
PersonFirstNameID <-- int PersonFirstNameID <-整数
PersonLastNameID <-- int PersonLastNameID <-整数
PersonSecurityID <-- int PersonSecurityID <-整数
PersonDetails 人员详细信息
PersonFirstNameID -CompositeKey PersonFirstNameID -CompositeKey
PersonLastNameID -CompositeKey PersonLastNameID -CompositeKey
PersonSecurityID -CompositeKey PersonSecurityID -CompositeKey
PersonDetailKey PersonDetailKey
PersonDetailValue PersonDetailValue
PersonDetailRisk PersonDetail风险
Now I want to model the one to many relation from Person to PersonDetails in NHibernate. 现在,我想在NHibernate中建立从Person到PersonDetails的一对多关系模型。
How can I do this? 我怎样才能做到这一点? I've tried setting up a component representing the composite Id and feeding this into the one to many via the property ref however this generate SQL with duplicate columns and throws the following: System.ArgumentException: Identifier type mismatch;
我尝试设置代表复合ID的组件,并通过属性ref将其馈入一对多,但是这会生成带有重复列的SQL,并引发以下错误:System.ArgumentException:Identifier type mismatch; Found: Expected:
发现:预期:
The NHibernate documentation talks only about doing this when the composite Id is the same on both.. NHibernate文档仅讨论在两个复合ID相同时执行此操作。
Yes... Its not my DB schema, its a legacy DB and access is very limited. 是的...不是我的数据库架构,它是旧式数据库,访问权限非常有限。
Not quite clear. 不太清楚。
For a foreign key relationship to work, the child must reference the primary key of the parent, so the data structure suggests that the primary key of person is FirstNameId/lastNameid/securityid (and hence your best move would be to ignore the personid column). 为了使外键关系正常工作,子级必须引用父级的主键,因此数据结构建议人员的主键为FirstNameId / lastNameid / securityid(因此,最好的做法是忽略personid列) 。
Is the Person_Id actually the primary key (defined as a PK in the DB), or is the database's version of PERSON primary key actually FirstNameId/lastNameid/securityid ? 是Person_Id实际上是主键(在数据库中定义为PK),还是数据库的PERSON主键版本实际上是FirstNameId / lastNameid / securityid?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.