--
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 nhusers+u...@googlegroups.com.
To post to this group, send email to nhu...@googlegroups.com.
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/groups/opt_out.
I'll try to explain my situation, sorry if the formulation of the phrases get bad, I'm using a translator.
--
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 nhusers+u...@googlegroups.com.
To post to this group, send email to nhu...@googlegroups.com.
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/groups/opt_out.
public class Role { public Role() { this.Roles = new List<Role>(); }
public virtual int Id { get; set; } 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 this mapping:
public class RoleMap : ClassMapping<Role> { public
RoleMap() { this.Table("ROLE"); this.Id(x => x.Id, m => m.Generator(Generators.HighLow)); this.Property(x => x.Name, m => { m.Column("name"); m.NotNullable(true); }); this.Property(x => x.Checked, m => { m.Column("checked"); m.NotNullable(true); }); this.ManyToOne(x => x.Parent, m => { m.Column("parent_id"); m.NotNullable(false); }); this.Bag(x => x.Roles, m => { m.Key(k => k.Column("parent_id")); m.Inverse(true); m.Cascade(Cascade.All | Cascade.DeleteOrphans); m.Lazy(CollectionLazy.NoLazy); }, r => r.OneToMany()); } }And these tests:
using (var session = sessionFactory.OpenSession()) using (session.BeginTransaction()) { var parent = new Role { Checked = true, Name = "Parent" }; var child = new Role { Parent = parent, Name = "Child" }; parent.Roles.Add(child);
session.Save(parent); session.Flush(); var roles = session.Query<Role>().ToList(); Debug.Assert(roles != null); Debug.Assert(roles.Count == 2); Debug.Assert(roles[0].Parent == null); Debug.Assert(roles[1].Parent == roles[0]); Debug.Assert(roles[0].Roles.Contains(roles[1])); }
object references an unsaved transient instance - save the transient instance before flushing or set cascade action for the property to something that would make it autosave. Type: Role, Entity: Role