many-to-one with multiple columns

自古美人都是妖i 提交于 2019-12-20 21:56:20

问题


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
  • UserId

Tasks

  • TaskId
  • AssignmentId
  • TaskName

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.

I'm trying to use this:

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

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


回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/2956925/many-to-one-with-multiple-columns

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