简体   繁体   English

流利的nhibernate外键,具有2列映射

[英]fluent nhibernate foreign key with 2 columns mapping

I have to an existing schema and I want to map it with nhibernate. 我必须有一个现有的架构,我想用nhibernate映射它。

entities / table schema: 实体/表架构:

post {
  pk_id
  prod_id
  prod_internid
  title
}

tag {
  pk_t_id
  prod_id
  prod_internid
  name
}

A post can have multiple tags and there is a foreign key contraint from the tag to the post table with the two columns prod_id and prod_internid. 一个帖子可以有多个标签,并且标签与帖子表之间的外键约束包含两列prod_id和prod_internid。

I've tried this: 我已经试过了:

PostMap {
  // tags is a list
  HasMany(x => x.tags).KeyColumns.Add("prod_id", "prod_internid");
}

TagMap {
  References(x => x.post).Columns("prod_id", "prod_internid");//.ForeignKey();
}

I get this error: 我收到此错误:

NHibernate.FKUnmatchingColumnsException: Foreign key (FK98806C8630C05A78:tag [prod_id, prod_internid])) must have same number of columns as the referenced primary key (post [pk_id])

How can I map it the right way? 我该如何正确映射它?

I don't think this functionality is currently supported in NHibernate but it is in Hibernate. 我认为NHibernate目前不支持此功能,但Hibernate中支持。 Seems like you or someone would need to port it over. 好像您或某人需要将其移植过来。 Take a look at this NH Issue: 看看这个NH问题:

https://nhibernate.jira.com/browse/NH-1722 https://nhibernate.jira.com/browse/NH-1722

I also found this previous StackOverflow article regarding this: 我还找到了有关此的上一篇StackOverflow文章:

many-to-one with multiple columns 多列一对多

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

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