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()方法。