-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNHibernateHelper.cs
43 lines (38 loc) · 1.21 KB
/
NHibernateHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FluentNHibernate;
using NHibernate;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using FluentNHibernateExample;
using FluentNHibernateExample.Mappings;
namespace FluentNHibernateExample
{
internal class NHibernateHelper
{
private static ISessionFactory _sessionFactory;
public static ISessionFactory SessionFactory
{
get
{
if (_sessionFactory == null)
{
string connectionString = "Data Source=NAIMURRAHMAN;Initial Catalog = productDetails;TrustServerCertificate=True; Trusted_Connection=True;";
_sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2012.ConnectionString(connectionString)
.ShowSql()) // Enables SQL logging
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<ProductMap>())
.BuildSessionFactory();
}
return _sessionFactory;
}
}
public static ISession GetSession()
{
return SessionFactory.OpenSession();
}
}
}