// 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 NHibernate; using NHibernate.Cfg; using log4net.Config; namespace E { public static class Util { private static long k = (new DateTime(1970, 1, 1, 0, 0, 0) + TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now)).Ticks; public static int N2U(DateTime dt) { return (int)((dt.Ticks - k) / 10000000); } public static DateTime U2N(int t) { return new DateTime(t * 10000000L + k); } } public class Dummy { public virtual int Id { get; set; } public virtual DateTime T1 { get; set; } public virtual DateTime T2 { get; set; } private DateTime t3; public virtual DateTime T3 { get { return t3; } set { t3 = value; } } public virtual int CvtT3 { get { return Util.N2U(t3); } set { t3 = Util.U2N(value); } } } public class Program { public static void Main(string[] args) { // log4net config XmlConfigurator.Configure(); // Hibernate config Configuration cfg = new Configuration(); cfg.Configure(); cfg.AddXmlFile("dummymapping.xml"); // open connection ISessionFactory sf = cfg.BuildSessionFactory(); ISession s = sf.OpenSession(); Dummy o = new Dummy { T1 = DateTime.Now, T2 = DateTime.Now, T3 = DateTime.Now }; s.Save(o); foreach(Dummy r in s.CreateQuery("FROM Dummy AS Dummy").List()) { Console.WriteLine(r.T1 + " " + r.T2 + " " + r.T3); } s.Close(); } } }