ForeignKey.EndsWith messes up multiple one-to-many relationships
Dear FluentNHibernate developers,
I recently had and issue with Fluent, which involved two one-to-many relationships between the same two entities. (the details are on SO.)
I always had ForeignKey.EndsWith("Id") within my convention collection, because I thought it was a very elegant way of expressing what I want.
The problem is, that when I have multiple many-to-one relationship between the same entites, Fluent can't figure out which property maps to which collection, but this is the least of the problems.
I set up a HasManyConvention and a ReferenceConvention (attached), in which I provided some logics about how to do it.
This is where things got messy: with ForeignKey.EndsWith, it actually created a third column for one of the entities, and the relationships didn't work. So in the end, I tried putting the naming into the HasMany and Reference conventions, and it just worked. I honestly don't know if this is by design or just an error, but for other people experiencing the same issue, it would be helpful if you wrote it in the wiki that it isn't working well in such scenarios.
Yours sincerely,
Timur Kristóf
- HasManyConvention.cs 2.3 KB
- ReferenceConvention.cs 698 Bytes
Support Staff 2 Posted by James Gregory on 16 May, 2010 05:22 PM
There have been some changes relating to foreign keys recently, specifically that a HasMany paired with a Reference will sync up their keys. That might make things a little better for you.
As for the
ForeignKey.EndsWith
convention, I've created an issue to investigate it.3 Posted by Timur Kristóf on 16 May, 2010 07:10 PM
I already created a HasMany and a Reference that work well together. I've attached them to the OP.
Thank you for your concern. :)