海阔天空

导航

Hibernate-配置文件

var configuration = new NH.Cfg.Configuration();

configuration.Configure(cfgPath);

Configuration对象创建后,需要调用Configure()方法来加载配置文件,hibernate默认在app.config和web.config中查找配置,也可以指定配置文件的位置,通常设置为程序输出目录(bin)下“hibernate.cfg.xml”文件。

 

程序方式配置

var configuration = new NH.Cfg.Configuration();

configuration.SetProperty("connection.provider", "NHibernate.Connection.DriverConnectionProvider");
configuration.SetProperty("dialect", dialect);
configuration.SetProperty("connection.driver_class", driver);
configuration.SetProperty("connection.connection_string", connectionString);
configuration.SetProperty("connection.release_mode", "on_close");
configuration.SetProperty("show_sql", "true");

configuration.AddAssembly("com.xxx");
configuration.AddAssembly("com.yyy");
configuration.AddAssembly("com.zzz");

Configuration对象创建后不需要调用Configure()方法。

posted on 2013-06-07 23:49  达芬奇  阅读(190)  评论(0编辑  收藏  举报