42 lines
1.8 KiB
C#
42 lines
1.8 KiB
C#
using System.Configuration;
|
|
using FluentNHibernate.Cfg;
|
|
using FluentNHibernate.Cfg.Db;
|
|
using FluentNHibernate.Conventions.Helpers;
|
|
using NHibernate.Cache;
|
|
using NHibernate.ByteCode.LinFu;
|
|
using Configuration = NHibernate.Cfg.Configuration;
|
|
|
|
namespace Taloyhtio.GeneralSSO.Server.CodeFiles.Infrastructure.DataAccess
|
|
{
|
|
public class NHConfiguration
|
|
{
|
|
public static Configuration Configure()
|
|
{
|
|
return build();
|
|
}
|
|
|
|
private static Configuration build()
|
|
{
|
|
var connectionString = ConfigurationManager.ConnectionStrings["Taloyhtio.GeneralSSO.Database"];
|
|
|
|
return Fluently.Configure()
|
|
.Database(
|
|
MsSqlConfiguration.MsSql2000
|
|
.Cache(c => c
|
|
.UseQueryCache()
|
|
.UseMinimalPuts()
|
|
.ProviderClass<HashtableCacheProvider>())
|
|
.ConnectionString(connectionString.ToString())
|
|
.ProxyFactoryFactory(typeof(ProxyFactoryFactory))
|
|
)
|
|
.Mappings(cfg => cfg.FluentMappings.AddFromAssemblyOf<NHConfiguration>()
|
|
.Conventions.Setup(mappings =>
|
|
{
|
|
mappings.AddAssembly(typeof(NHConfiguration).Assembly);
|
|
mappings.Add(ForeignKey.EndsWith("Id"));
|
|
mappings.Add<EnumConvention>(); // custom EnumConvention is needed in order to map enum? to int?
|
|
})).BuildConfiguration();
|
|
}
|
|
}
|
|
}
|