Got it!

My class:

public class Role : EntityBase<Role, int>
    {
        public virtual string Name { get; set; }
        public virtual bool Checked { get; set; }
        public virtual Role Parent { get; set; }
        public virtual IList<Role> Roles { get; set; }
    }

and my map:

public class RoleMap : ClassMapping<Role>
    {
        public RoleMap()
        {
            Table("ROLE");

            Id(x => x.Id);

            Property(x => x.Name, m =>
            {
                m.Column("name");
                m.NotNullable(true);
            });

            Property(x => x.Checked, m =>
            {
                m.Column("checked");
                m.NotNullable(true);
            });

            ManyToOne(x => x.Parent, m =>
                                         {
                                             m.Column("parent_id");
                                             m.NotNullable(false);
                                         });

            Bag(x => x.Roles, m =>
                                  {
                                      m.Key(k => k.Column("parent_id"));
                                      m.Inverse(true);
                                      m.Cascade(Cascade.DeleteOrphans);
                                      m.Lazy(CollectionLazy.NoLazy);
                                  }, r => r.OneToMany());
        }
    }

Thanks for helping


2013/10/7 Ricardo Peres <[email protected]>

> It does. You will need to mark the Parent property as not required (for
> the top-level nodes).
> What problems are you facing?
>
> RP
>
>
> On Monday, October 7, 2013 2:02:08 PM UTC+1, Tiago Azevedo wrote:
>
>> I want to build a hierarchical tree
>>
>> Like
>>
>> -Node
>>          .Node(leaf)
>>          .Node(leaf)
>>          -Node
>>                      .Node(leaf)
>>                      .Node(leaf)
>> -Node
>>          .Node(leaf)
>>          .Node(leaf)
>>
>> To have this I thought in the class shown in the first post,
>> theoretically work since I can do the mapping correctly.
>>
>>
>> 2013/10/6 Ricardo Peres <[email protected]>
>>
>>> Tiago,
>>>
>>> I can't understand you, can you explain better?
>>>
>>> RP
>>>
>>>
>>> On Tuesday, October 1, 2013 1:48:07 PM UTC+1, Tiago Azevedo wrote:
>>>>
>>>> I managed to create the table in the database with this mapping,
>>>> however the list in my repository back to the property Roles own class
>>>> instead of their children.
>>>> I made only one Session.Query <role> (). I would have to do some
>>>> treatment to bring the list correctly?
>>>>
>>>> Em terça-feira, 1 de outubro de 2013 08h48min47s UTC-3, Ricardo Peres
>>>> escreveu:
>>>>>
>>>>> Sure:
>>>>>
>>>>> var mapper = new ModelMapper();
>>>>> mapper.Class<MyClass>(ca =>
>>>>> {
>>>>> ca.Id(x => x.Id, map =>
>>>>>  {
>>>>> map.Column("myclass_id");
>>>>> map.Generator(Generators.**Ident**ity);
>>>>>  });
>>>>> ca.Property(x => x.Name, a =>
>>>>> {
>>>>>  //fill in the blanks
>>>>>  });
>>>>> ca.ManyToOne(c => c.Parent, a =>
>>>>> {
>>>>> map.Column("parent_id");
>>>>>  //fill in the blanks
>>>>> });
>>>>> ca.Bag(c => c.ListClass, c =>
>>>>>  {
>>>>> c.Key(x => x.Column("myclass_id"));
>>>>> c.Inverse(true);
>>>>>  //fill in the blanks
>>>>> }, c => c.OneToMany());
>>>>> }
>>>>>
>>>>> What exactly is your problem?
>>>>>
>>>>> RP
>>>>>
>>>>> On Monday, September 30, 2013 9:07:15 PM UTC+1, Tiago Azevedo wrote:
>>>>>>
>>>>>> Someone could tell how to perform the mapping of this class?
>>>>>>
>>>>>> public class MyClass
>>>>>> {
>>>>>> public virtual int Id { get; set; }
>>>>>> public virtual string Name { get; set; }
>>>>>> public virtual Role Parent { get; set; } // or public virtual int
>>>>>> ParentId { get; set; } ???
>>>>>> public virtual IList<MyClass> ListClass{ get; set; }
>>>>>>  }
>>>>>>
>>>>>  --
>>> You received this message because you are subscribed to a topic in the
>>> Google Groups "nhusers" group.
>>> To unsubscribe from this topic, visit https://groups.google.com/d/**
>>> topic/nhusers/qIJlAN0vuXM/**unsubscribe<https://groups.google.com/d/topic/nhusers/qIJlAN0vuXM/unsubscribe>
>>> .
>>> To unsubscribe from this group and all its topics, send an email to
>>> nhusers+u...@**googlegroups.com.
>>> To post to this group, send email to [email protected].
>>>
>>> Visit this group at 
>>> http://groups.google.com/**group/nhusers<http://groups.google.com/group/nhusers>
>>> .
>>> For more options, visit 
>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
>>> .
>>>
>>
>>
>>
>> --
>> Tiago Azevedo Borges
>> Goiânia - Goiás
>>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "nhusers" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/nhusers/qIJlAN0vuXM/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/nhusers.
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
Tiago Azevedo Borges
Goiânia - Goiás

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to