我用流利的NHibernate和需要得到从我的连接字符串的hibernate.cfg.xml connection.connection_string财产文件创建我的会话工厂:如何从hibernate.cfg.xml文件中获取连接字符串值?
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();
}
}
我想更换MyConnStr (即在我的web.config文件中)“c => c.FromConnectionStringWithKey(”MyConnStr“)”用于来自hibernate.cfg.xml文件的连接字符串。
我试过使用NHibernate.Cfg.Environment.ConnectionString,但它没有工作。
我怎样才能得到这个?
谢谢。
谢谢,但我需要得到这个在我的SessionFactory吸气。我想要NHibernate连接字符串来创建我的SessionFactory。我使用流利NHibernate。 – MCardinale
@MCardinale - 工厂应该原生使用此连接字符串,您需要更改它或...? –
我编辑了我的问题,添加了我的SessionFactory的代码。我想使用来自NHibernate的连接字符串而不是Web.config或硬编码的字符串,因为此工厂位于类库中以便在其他项目中重用。非常感谢你。 – MCardinale