Free Hierarchical Data NHibernate

Hey everyone. Quick question about fluent syntax. I thought I got it right, but I'm having a weird failure. Basically I have a hierarchical structure that I am trying to keep and it all works, except when I do an actual w / db integration test.

I have a Node object that has a Parent property which is another Node and a _children field that supports the readonly Children property which is also a collection of nodes.

The property handler that correlates the relationship and the objects in memory are validated just fine. When I check them out from the repository (in-memory SQLite db in my tests) even though any of them Node Children includes for some reason. Any ideas?

My mappings are mostly done w / AutoMap, but I've overridden the following:

mapping.References(x => x.Parent);
mapping.HasMany(x => x.Children).Inverse().Access.LowerCaseField(Prefix.Underscore);

      

I also tried this without calling Inverse ().

+2


source to share


1 answer


Got it. The problem was that I needed to tell the child collection about which Id field to connect to the foreign key.

I changed this mapping this way:



mapping.HasMany(m => m.Children)
  .Inverse()
  .KeyColumn("ParentId")
  .Access.CamelCaseField(Prefix.Underscore)
  .Cascade.All()

      

+3


source