Reputation: 36339
Hey all. Quick question on Fluent syntax. I had thought I had this down, but I'm getting a weird failure. Basically, I have a hierarchical kind of structure that I'm trying to persist, and it all seems to work, except when I do an actual integration test w/ the db.
I have a Node object which has a Parent property, which is another Node, and a _children field backing a readonly Children property, which is a collection of Nodes as well.
The properties handle correlating the relationships, and the in-memory objects test out just fine. When I retrieve them from the repository (an in-memory SQLite db in my tests), though, any Node's Children include itself 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've also tried it w/o the Inverse() call.
Upvotes: 2
Views: 1010
Reputation: 36339
Got it. The problem was that I needed to tell the children collection what Id field to hook into for the foreign key.
I changed that mapping to look like so:
mapping.HasMany(m => m.Children)
.Inverse()
.KeyColumn("ParentId")
.Access.CamelCaseField(Prefix.Underscore)
.Cascade.All()
Upvotes: 3