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 <mcfaz...@gmail.com> 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 fluent-nhibernate@googlegroups.com
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to