nhibernate會在每次有人發出請求時解析xml文件,或者每次應用程序啓動時解析xml文件?nhibernate開始執行
那麼這裏就是即時通訊做:
public class SessionManager
{
private readonly ISessionFactory _sessionFactory;
public SessionManager()
{
_sessionFactory = GetSessionFactory();
}
public ISession GetSession()
{
return _sessionFactory.OpenSession();
}
private static ISessionFactory GetSessionFactory()
{
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2005
.ConnectionString(c =>
c.Is(
@"Data Source=Pc-De-Yassir;Initial Catalog=MyDatabase;User Id=sa;Password=password;Integrated Security=True")
))
.Mappings(m =>
m.AutoMappings.Add
(
AutoPersistenceModel.MapEntitiesFromAssemblyOf<Model.Category>()
))
.BuildSessionFactory();
}
}
,這裏是我如何從數據庫中獲取數據
public IList<Category> GetCategories()
{
var session = new SessionManager().GetSession();
return session.CreateCriteria(typeof(Category))
.List<Category>();}
所以我的問題是將NHibernate的配置本身第一次遇到這種運行的方法每次發出請求?
..這應該在應用程序啓動時發生一次。 – 2009-06-25 10:54:30