Parent/child self-referential relationships, auto-mapping
Given
public class Category : Entity {
public virtual IList<Category> Children { get; set; }
public virtual Category Parent { get; set; }
}`
Automapping wishes to spit out this
<bag inverse="true" name="Children" table="ChildrenToChildren" mutable="true"> <key> <column name="CategoryFk" /> </key> <many-to-many class="[blah].Model.Category, [blah].Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"> <column name="CategoryFk" /> </many-to-many> </bag> <many-to-one class="[blah].Model.Category, [blah].Model, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" name="Parent"> <column name="ParentId" /> </many-to-one>
and also starts complaining about duplicated column names obviously.
All I really want is a parent column, a self-referential relationship and not to have to delve into manual wiring (not that fluent isn't less painful than HBMing it, just that the model may change at runtime later ...)
What am I missing?
Support Staff 2 Posted by James Gregory on 04 May, 2010 03:05 PM
We've got an open issue for self-referential support in the automapper,
http://fluentnhibernate.lighthouseapp.com/projects/33236/tickets/115-self-referencing-relationships,
but there's been a general lack of interest in it so it was pushed until the
2.0 release. If you shout loud enough I might be tempted to move it to 1.1
;)
3 Posted by Matthew McLeod on 04 May, 2010 03:23 PM
Consider this extreme interest.
WOULD CAPS COUNT AS YELLING?
I've begun work on a web-based graphical modelling tool (half class designer, more uml-ish) and the system is talking to a quite large (and well entrenched) enterprise architecture / knowledge management tool. I've been pushing for the tool to push out some persistent assemblies in .net (the rest of the tool is smalltalk), and I'm running with an Nhibernate tool stack - automapping in this case is sort of mandatory, as mapping overrides aren't going to happen at runtime.
Please?
4 Posted by Devon Lazarus on 04 May, 2010 03:27 PM
Wow. I was unaware of that.
This will be a critical need for us as we are using the Composite Pattern extensively. Please add my humble shouting to the list of requests for seeing this in 1.1
/me goes to login to lighthouse
-devon
Support Staff 5 Posted by James Gregory on 04 May, 2010 03:38 PM
Shouting noted guys, I'll move the ticket to 1.1.
Support Staff 6 Posted by James Gregory on 14 May, 2010 02:20 AM
I've just committed revision
d2f8f58
which, among other things, should fix these self-referential relationships.If you're able to update to the latest version, feedback would be appreciated.
7 Posted by Matthew McLeod on 14 May, 2010 05:45 AM
Latest download .zip from the fluent page (#656) magically missing
http://github.com/jagregory/fluent-nhibernate/blob/master/src/FluentNHibernate/CombinedAssemblyTypeSource.cs
somehow.
--
Matthew McLeod
Support Staff 8 Posted by James Gregory on 14 May, 2010 02:48 PM
Should be fixed in 657, when it shows up on the downloads page. Was a bug in our zip build task, still not perfect but at least all the files are there now.
9 Posted by Joan on 12 Nov, 2010 09:49 PM
Was the cascade deleting of self-reference object added to the fix of the mapping? I can make the mapping work. but delete cascade not working. Also if I delete the child object, the parent object didn't update it's Child list.
class are like this:
public class MyItemClass
{ public virtual IObservableList Children { get; set; } }
public class MyItemClassMap : ClassMap
{
}
Any info is appreciated.
Joan