我正在使用以下代码来创建Session Factory
带有 NHibernate 的。我想用相对路径来指定这个路径,这样当我和我的队友合并我们的分支时,我们就不必一直修复连接字符串。我怎样才能做到这一点?
private static void InitializeSessionFactory(bool deleteSchemaOnClosing = false, bool regenerateSchemaOnOpening = false)
{
_sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(
@"Data Source=.\SQLEXPRESS;AttachDbFilename=""C:\MyProject\MyProjectCore\Fluent NHibernate\CoreDatabase.mdf"";Integrated Security=True;User Instance=True")
.ShowSql()
)
.Mappings(m =>
m.FluentMappings
.AddFromAssemblyOf<User>())
.ExposeConfiguration(cfg => new SchemaExport(cfg)
.Create(deleteSchemaOnClosing,regenerateSchemaOnOpening))
.BuildSessionFactory();
}
我的app.config
文件如下所示:
<?xml version="1.0"?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="CoreDatabase.Properties.Settings.CoreDatabaseConnectionString"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\CoreDatabase.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
<add name="Fluent_NHibernate.Properties.Settings.CoreDatabaseConnectionString"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\CoreDatabase.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/></startup></configuration>
谢谢!