我想从app.config和appSettingKey配置我的NHibernate Fluent.
是否有人可以解释app.config文件应该如何?
MsSqlConfiguration.MsSql2005
.ConnectionString(c => c
.FromAppSetting("appSettingKey"));
Run Code Online (Sandbox Code Playgroud)
这是我的connectionsString
Data Source=(local);Initial Catalog=ABC;Integrated Security=True
Run Code Online (Sandbox Code Playgroud)
这不起作用:
<appSettingKey>"Data Source=.;Initial Catalog=ABC;Integrated Security=True"</appSettingKey>
Run Code Online (Sandbox Code Playgroud)
// Mats,斯德哥尔摩,瑞典
如果我理解正确,您希望在示例中配置Fluent NHibernate并使用App.config中的连接字符串.下面是我将如何实现这一目标的一个例子.
App.config中:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="FluentNHibernateConnection"
value="server=.;Initial Catalog=YourDB;Integrated Security=True" />
</appSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
用于创建会话工厂的代码:
private static ISessionFactory CreateSessionFactory()
{
var fluentConfig = MsSqlConfiguration.MsSql2005
.ConnectionString.FromAppSetting("FluentNHibernateConnection");
PersistenceModel persistenceModel = new PersistenceModel();
persistenceModel.addMappingsFromAssembly(typeof(User).Assembly);
Configuration nhConfig = new Configuration()
.AddProperties(fluentConfig.ToProperties());
persistenceModel.Configure(nhConfig);
return nhConfig.BuildSessionFactory();
}
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你.
/ Erik("Stockholmare"的同事)
| 归档时间: |
|
| 查看次数: |
4438 次 |
| 最近记录: |