NHibernate tunning
private static ISessionFactory CreateSessionFactory1()
{
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("Sql2008")))
//.Cache(c=>c.UseSecondLevelCache().ProviderClass(typeof(NHibernate.Caches.SysCache.SysCacheProvider).AssemblyQualifiedName))
//.Cache(c => c.UseQueryCache().ProviderClass(typeof(NHibernate.Caches.SysCache.SysCacheProvider).AssemblyQualifiedName))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Program>())
.BuildConfiguration()
#region cache configuration
.SetProperty(NHibernate.Cfg.Environment.UseSecondLevelCache, "true")
.SetProperty(NHibernate.Cfg.Environment.UseQueryCache, "true")
.Cache(c =>
{
c.Provider<NHibernate.Caches.SysCache.SysCacheProvider>();
// c.DefaultExpiration = 1;
})
#endregion
#region configure cache on Movies Entity
.EntityCache<Movies>(c =>
{
c.Strategy = EntityCacheUsage.ReadWrite;
c.RegionName = "Region1";
})
#endregion
.BuildSessionFactory();
}
using (var session = sessionFactory.OpenSession())
{
// var m8 = session.CreateCriteria(typeof(Movies)).Add(Restrictions.Eq("Genre", "Guerre1234")).UniqueResult<Movies>();
//var m8 = session.Get<Movies>(2);
var m8 = session.CreateQuery("from Parent10 p where p.id1 =: id1 and p.id2 =: id2")
.SetString("id1", "1")
.SetString("id2", "2")
.SetCacheable(true)
.SetCacheRegion("Region1")
.Future<Parent10>()
//.Enumerable<Parent10>()
.First<Parent10>();
// Console.WriteLine("Id > " + m8.id1 + "Genre > " + m8.id2 + " Price > " + m8.ParentName);
//Console.ReadLine();
// m8.Price = 2; session.Flush();
// session.Close();
Console.WriteLine("End Session 1");
}
using (var session = sessionFactory.OpenSession())
{
//var m8 = session.CreateCriteria(typeof(Movies)).Add(Restrictions.Eq("Genre", "Guerre1234")).UniqueResult<Movies>();
var m8 = session.CreateQuery("from Parent10 p where p.id1 =: id1 and p.id2 =: id2")
.SetString("id1", "1")
.SetString("id2", "2")
.SetCacheable(true)
.SetCacheRegion("Region1")
.Future<Parent10>()
//.Enumerable<Parent10>()
.First<Parent10>();
// Console.WriteLine("Id > " + m8.id1 + "Genre > " + m8.id2 + " Price > " + m8.ParentName);
var m9 = session.CreateQuery("from Parent10 p where p.id1 =: id1 and p.id2 =: id2")
.SetString("id1", "1")
.SetString("id2", "3")
.SetCacheable(true)
.SetCacheRegion("Region1")
.Future<Parent10>()
//.Enumerable<Parent10>()
.First<Parent10>();
Console.Read();
var m10 = session.CreateQuery("from Parent10 p where p.id1 =: id1 and p.id2 =: id2")
.SetString("id1", "1")
.SetString("id2", "2")
.SetCacheable(true)
.SetCacheRegion("Region1")
.Future<Parent10>()
//.Enumerable<Parent10>()
.First<Parent10>();
// Console.ReadLine();
//session.Close();
Console.WriteLine("End Session 2");
}
No comments:
Post a Comment