我正在使用 Fluent NHibernate,需要从 hibernate.cfg.xml 文件的 connection.connection_string 属性中获取我的连接字符串以创建我的 session 工厂:
private static ISessionFactory SessionFactory {
get {
return = Fluently.Configure()
.Database(MySQLConfiguration.Standard.ConnectionString(c => c.FromConnectionStringWithKey("MyConnStr")))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<FooMap>())
.ExposeConfiguration(c => c.Properties.Add("hbm2ddl.keywords", "none"))
.BuildSessionFactory();
}
}
我想为 hibernate.cfg 中的连接字符串替换 MyConnStr(在我的 web.config 文件中)“c => c.FromConnectionStringWithKey("MyConnStr")” .xml 文件。
我试过使用 NHibernate.Cfg.Environment.ConnectionString,但没有用。
我怎样才能得到这个?
谢谢。
最佳答案
试试这个
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration().Configure();
string conString = cfg.Configuration.GetProperty(NHibernate.Cfg.Environment.ConnectionString);
关于c# - 如何从 hibernate.cfg.xml 文件中获取连接字符串值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2432628/