Thanks, It seems like the manual override is the only way and that there is no automapping feature that handles these self-referential tree structures.
On May 28, 9:20 am, JoseFR <[email protected]> wrote: > I've an entity like yours and I've to override his mapping like this: > > Entity: > public class Account : Entity > { > public virtual string Name { get; set; } > public virtual Account ParentAccount{get; set;} > public virtual IList<Account> ChildrenAccount {get;set;} > protected Account() { } > > public Account(string accountName) > { > this.Name = accountName; > } > } > > Configuration: > AddEntityAssembly.BlaBlaBla.ForTypesThatDeriveFrom<Account > > (AccountCustomMap) > > then: > > Private static void AccountCustomMap(AutoMap<Account> obj) > { > obj.HasMany(x => x.ChildrenAccount ) > .Cascade.All() > .KeyColumnNames.Add("ParentAccount_Id") //Be carefull > with your conventions > .Inverse(); > } > > I hope this help you. > > BTW: I've this same problem with the same domain. haha > > On May 27, 12:49 pm, Chris Fazeli <[email protected]> wrote: > > > Hello, > > > I have an Account entity: > > > public class Account : Entity > > { > > public virtual string Name { get; set; } > > > protected Account() { } > > > public Account(string accountName) > > { > > this.Name = accountName; > > } > > } > > > I'm trying to setup my entity so that it can have an (optional) parent > > entity of type Account, and 0-to-many children of type Account. I'm > > also trying to leverage the FNH automapper to have this work. > > > When I insert: > > public virtual Account Parent { get; set; } > > > the automapping works fine after I create the FK relationship in my > > DB: > > > Account > > ------------ > > int AccountId > > int ParentFk > > nvarchar(100) Name > > > However, when I also insert: > > public virtual IList<Account> Children { get; set; } > > > my S#arp Architecture CanConfirmDatabaseMatchesMappings test fails > > with the error: > > > NHibernate Mapping Exception: Repeated column in mapping for > > collection: MyNamespace.Account.Children column: Account_id > > > I've found posts for mapping trees using an HBM file, as well as > > Fluent NHibernate, but I can't figure it out using the automapping > > feature. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en -~----------~----~----~----~------~----~------~--~---
