static void Main(string[] args) { var configuration = Fluently.Configure() .Database(MsSqlConfiguration.MsSql2008.ConnectionString(s => s.FromConnectionStringWithKey("DB")).ShowSql) .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Program>().ExportTo(Console.Out)) .ExposeConfiguration(cfg => new SchemaExport(cfg).Execute(true,true,false)); var sessionFactory = configuration.BuildSessionFactory(); using (var session = sessionFactory.OpenSession()) using (var transaction = session.BeginTransaction()) { var top = new Organisation("Top Level"); top.AddChild(new Organisation("Child 1")); new Organisation("Child 2", top); session.Save(top); transaction.Commit(); } using (var session = sessionFactory.OpenSession()) using(var transaction = session.BeginTransaction()) { var topLevel = session.QueryOver<Organisation>().Where(o => o.Name == "Top Level").SingleOrDefault(); foreach (var subItem in topLevel.Children) { Console.WriteLine(subItem.Name); } transaction.Commit(); } Console.ReadLine(); }
public virtual void AddChild(Organisation child) { child.Parent = this; _children.Add(child); }
public Organisation(string name, Organisation parent) : this(name) { if (parent == null) throw new ArgumentNullException("parent"); parent.AddChild(this); }