Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

many-to-one with multiple columns

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?

like image 360
Sly Avatar asked Jun 02 '10 10:06

Sly


1 Answers

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.

like image 127
Jamie Ide Avatar answered Sep 20 '22 15:09

Jamie Ide