fluent nhibernate foreign key with 2 columns mapping

别来无恙 提交于 2019-12-25 02:59:58

问题


I have to an existing schema and I want to map it with 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.

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?


回答1:


I don't think this functionality is currently supported in NHibernate but it is in Hibernate. Seems like you or someone would need to port it over. Take a look at this NH Issue:

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

I also found this previous StackOverflow article regarding this:

many-to-one with multiple columns



来源:https://stackoverflow.com/questions/12463136/fluent-nhibernate-foreign-key-with-2-columns-mapping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!