// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Collections; using NHibernate; using NHibernate.Cfg; using log4net.Config; namespace Test.Hibernate { public class T1 { private int f1; private string f2; public int F1 { get { return f1; } set { f1 = value; } } public string F2 { get { return f2; } set { f2 = value; } } } public class TestClass { public static void SelectOne() { Configuration cfg = new Configuration(); cfg.AddXmlFile("t1mapping.xml"); ISessionFactory sf = cfg.BuildSessionFactory(); ISession s = sf.OpenSession(); T1 r = (T1)s.Load(typeof(T1), 2); Console.WriteLine(r.F1 + " " + r.F2); s.Close(); } public static void SelectAll() { Configuration cfg = new Configuration(); cfg.AddXmlFile("t1mapping.xml"); ISessionFactory sf = cfg.BuildSessionFactory(); ISession s = sf.OpenSession(); IList all = s.Find("FROM T1 AS t1"); for(int i = 0; i < all.Count; i++) { T1 r = (T1)all[i]; Console.WriteLine(r.F1 + " " + r.F2); } s.Close(); } public static void Main(string[] args) { XmlConfigurator.Configure(); SelectOne(); SelectAll(); } } }