3

app.config と appSettingKey から NHibernate Fluent を構成したいと考えています。

ファイルapp.configがどのように見えるべきかを説明できる人はいますか?

MsSqlConfiguration.MsSql2005  
   .ConnectionString(c => c  
    .FromAppSetting("appSettingKey")); 

そして、これは私の接続文字列です

Data Source=(local);Initial Catalog=ABC;Integrated Security=True

これは機能しません:

<appSettingKey>"Data Source=.;Initial Catalog=ABC;Integrated Security=True"</appSettingKey>

// マッツ、ストックホルム、スウェーデン

4

3 に答える 3

9

私があなたを正しく理解していれば、例のように 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>

セッション ファクトリを作成するコード:

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();
}

それが役に立てば幸い。

/エリック(「ストックホルマー」の仲間)

于 2009-02-22T08:35:24.543 に答える
1

FluentNHibernatewikiのデータベース構成を読んでください。

于 2009-02-22T13:32:08.807 に答える
0
Fluently.Configure()
                .Database(
                    MsSqlConfiguration.MsSql2008.ConnectionString(
                                c => c.FromConnectionStringWithKey(connectStringKey)
                            )//End ConnectionString
                        )//End Database
                .Mappings(m =>m.FluentMappings.AddFromAssemblyOf<ADomainClassType>())
                .BuildSessionFactory();

これが、セッションファクトリーを構築する方法です。

于 2012-07-15T16:04:13.167 に答える