流利的nhibernate外键与2列映射 [英] fluent nhibernate foreign key with 2 columns mapping

查看:189
本文介绍了流利的nhibernate外键与2列映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



实体/表格架构:

 发布{
pk_id
prod_id
prod_internid
title
}

tag {
pk_t_id
prod_id
prod_internid
名称
}

帖子可以有多个标签,从标签到包含两列prod_id和prod_internid的帖子表有一个外键约束。



这:

  PostMap {
// tags是一个列表
HasMany(x => x。标签).KeyColumns.Add(prod_id,prod_internid);


TagMap {
引用(x => x.post).Columns(prod_id,prod_internid); //。ForeignKey();

code


我得到这个错误:

pre $ NHibernate.FKUnmatchingColumnsException:外键(FK98806C8630C05A78:tag [prod_id,prod_internid]))必须与引用的主键(post [pk_id])具有相同的列数

如何以正确的方式映射它?

解决方案

我不认为NHibernate当前支持这个功能,但它在Hibernate中。看起来像你或某人需要将其移交。看看这个NH问题:



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



我也发现这篇关于这个的以前的StackOverflow文章:



多对一的多列 a>


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?

解决方案

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

这篇关于流利的nhibernate外键与2列映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆