NHibernateHelper.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using NHibernate;
  2. using NHibernate.Cfg;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace TaskDatabase
  9. {
  10. public class NHibernateHelper
  11. {
  12. private static object lockObj = new object();
  13. private static ISessionFactory _sessionFactory;
  14. private static ISessionFactory SessionFactory
  15. {
  16. get
  17. {
  18. if (_sessionFactory == null)
  19. {
  20. lock (lockObj)
  21. {
  22. if (_sessionFactory == null)
  23. {
  24. var configuration = new Configuration();
  25. configuration.Configure();
  26. //configuration.AddAssembly(typeof(TaskModel).Assembly);
  27. _sessionFactory = configuration.BuildSessionFactory();
  28. }
  29. }
  30. }
  31. return _sessionFactory;
  32. }
  33. }
  34. public static ISession OpenSession()
  35. {
  36. return SessionFactory.OpenSession();
  37. }
  38. }
  39. }