许多对一具有多个列 [英] many-to-one with multiple columns

查看:110
本文介绍了许多对一具有多个列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个遗留数据的基础上,并在两个表之间的关系的一对之一。问题是,相对于使用两个列,没有之一。是否有某种方式在NHibernate中说,得到一个引用的实体时,它使用的两列连接语句,不是吗?
我有一个类似的表结构

I have a legacy data base and a relation one-to-one between two tables. The thing is that relation uses two columns, not one. Is there some way to say in nhibernate that when getting a referenced entity it used two columns in join statement, not one? I have a similar table structure

TaskProgress


  • ProgressId

  • TASKID

  • AssignmentId

  • 用户ID

  • ProgressId
  • TaskId
  • AssignmentId
  • UserId

任务


  • TASKID

  • AssignmentId

  • TASKNAME

每个任务可以在不同的任务asigned。 ,这意味着对任务进度独特的任务只能由AssignmentId和TASKID字段来建立

Each task can be asigned in different assignments. That mean that unique task for task progress can be founded only by AssignmentId and TaskId fields.

我试图用这个:

  References(x => x.Template)
            .Columns()
            .PropertyRef()

但不能得到如何映射加入多个列,任何想法?

But can't get how to map join on multiple columns, any ideas?

推荐答案

我是从你的示例代码使用PropertyRef的那两列没有形成一个复合主键假设。如果是这样的话,那么你的运气了,因为财产裁判只能接受一个属性。在评论中问题NH-1722 ,此功能可显然在Hibernate中,但还没有。被移植到NHibernate的

I'm assuming from your use of PropertyRef in the sample code that the two columns do not form a composite primary key. If that's the case, then you're out of luck because property-ref can only accept one property. Judging by the comments in issue NH-1722, this functionality apparently available in Hibernate but has not been ported to NHibernate.

更新:
架构添加你看起来像一个多到很多与任务和分配之间的其他数据的关系。 TaskProgress是任务和分配之间的联系表。如果TaskProgress没有额外的用户ID字段,那么你可以模拟这是一个简单的多到多。因为链接表具有附加数据它变得更复杂。

Update: The schema you added looks like a many-to-many with additional data relationship between Task and Assignment. TaskProgress is the link table between Task and Assignment. If TaskProgress did not have the additional UserId field then you could model this as a simple many-to-many. Because the linking table has additional data it gets a bit more complicated.

多对一许多具有附加数据通常是由创建代表链接表中的一个对象模型(TaskProgress )和建模的关系作为两个一对多的关系。也就是说,任务和分配有TaskProgress一到多的关系。 TaskProgress有任务,分配和用户属性。

Many-to-many with additional data is usually modeling by creating an object representing the linking table (TaskProgress) and modeling the relationship as two one-to-many relationships. That is, Task and Assignment have one-to-many relationships with TaskProgress. TaskProgress has properties for Task, Assignment, and User.

这篇关于许多对一具有多个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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