namespace TstDBConnection.Entities{ public class Tree { public virtual Guid Id { get; set; } public virtual string Name { get; set; } }}
namespace TstDBConnection.Entities{ public class Leaf { public virtual Guid Id { get; set; } public virtual string Name { get; set; } public virtual Tree Tree { get; set; } }}
public static void TestMany2One(ISessionFactory sessionFactory) { using (ISession session = sessionFactory.OpenSession()) { Tree tree = new Tree() { Name = "Big Tree" }; Leaf leaf = new Leaf() { Tree = tree, Name = "Leaf A for Big Tree" }; session.Save(leaf); session.Flush(); var query = from leafT in session.Query () select leafT; IList employees = query.ToList(); } }
static void Main(string[] args) { log4net.Config.XmlConfigurator.Configure(); // log4net Configuration configuration = new Configuration(); configuration.Configure(); ISessionFactory sessionFactory = configuration.BuildSessionFactory(); TestMany2One(sessionFactory); sessionFactory.Close(); }