// 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 System.Collections.Generic; using System.Linq; using NHibernate; using NHibernate.Cfg; using NHibernate.Linq; using log4net.Config; namespace E { public class T1 { public virtual int F1 { get; set; } public virtual string F2 { get; set; } } public class Program { public static void Main(string[] args) { XmlConfigurator.Configure(); Configuration cfg = new Configuration(); cfg.Configure("hibernateconfig.xml"); cfg.AddXmlFile("t1mapping.xml"); ISessionFactory sf = cfg.BuildSessionFactory(); using(ISession s = sf.OpenSession()) { IList res1 = s.CreateQuery("FROM T1 AS t1").List(); Console.WriteLine(res1.GetType().FullName); foreach(T1 o in res1) { Console.WriteLine(o.F1 + " " + o.F2); } IList res2 = s.CreateQuery("FROM T1 AS t1").List(); Console.WriteLine(res2.GetType().FullName); foreach(T1 o in res2) { Console.WriteLine(o.F1 + " " + o.F2); } IList res3 = (from t1 in s.Linq() select t1).ToList(); Console.WriteLine(res3.GetType().FullName); foreach(T1 o in res3) { Console.WriteLine(o.F1 + " " + o.F2); } //IList res4 = (from t1 in s.Linq() select t1).ToList(); IList res4 = (from t1 in s.Linq() select t1).ToList(); Console.WriteLine(res4.GetType().FullName); foreach(T1 o in res4) { Console.WriteLine(o.F1 + " " + o.F2); } List res5 = (from t1 in s.Linq() select t1).ToList(); Console.WriteLine(res5.GetType().FullName); foreach(T1 o in res5) { Console.WriteLine(o.F1 + " " + o.F2); } } } } }