I have implement testing app. which uses fluent nhibernate mapping to db object inside mssql db. Since I want to learn fine tune nhib. mvc3 applications, I m using this app. for testing purposes which have only one simple entity with 10 enum properties and one string property. So, it is really lightwave, yet startup time according to nhibernate profiler is 4.37 sec. Which is really slow for rendering one entity with few lines checked/unchecked property.
Code is the following. Domain.SessionProvider.cs
public static ISessionFactory CreateSessionFactory()
{
var config = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(c => c.FromConnectionStringWithKey("myConnection")))
.Mappings(m => m.FluentMappings.Add<FeaturesMap>())
.ExposeConfiguration(p => p.SetProperty("current_session_context_class", "web"))
.BuildConfiguration();
return config.BuildSessionFactory();
}
<强 > 全球.asax 强 >
public class MvcApplication : System.Web.HttpApplication
{
//SessionPerWebRequest is ommited here as well as other content
public static ISessionFactory SessionFactory =
SessionProvider.CreateSessionFactory();
protected void Application_Start()
{
SessionFactory.OpenSession();
}
}
在我的主计长内部,我有以下内容:
public ActionResult Index()
{
return View(GetData());
}
private IList<FeaturesViewModel> GetData()
{
List<Features> data;
using (ISession session = MvcApplication.SessionFactory.GetCurrentSession())
{
using (ITransaction tx = session.BeginTransaction())
{
data = session.Query<Features>().Take(5).ToList();
tx.Commit();
var viewModelData = FeaturesViewModel.FromDomainModel(data);
return viewModelData;
}
}
}