4
これはFluent NHに関する私の最初の試みです。私はProperties.Settingsに接続文字列を格納します。FluentNHibernate SQL Serverの設定。 connectionstringの問題
FnhDbString = Data Source=PC\SQLEXPRESS;Initial Catalog=FNHTest;Integrated Security=True
私は.FromAppSetting
と流暢設定した場合、私は例外を取得:
ArgumentNullException
Value cannot be null. Parameter name: Data Source
私は.FromConnectionStringWithKey
と流暢設定した場合、私は例外を取得:
NullReferenceException
Object reference not set to an instance of an object.
フル方法:
private static ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(c => c
.FromAppSetting(Properties.Settings.Default.FnhDbString))
.Cache(c => c
.UseQueryCache()).ShowSql())
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Product>())
.BuildSessionFactory();
}
...
ここで私は何が間違っていますか?
ありがとう!それはうまくいった。 :) – bretddog
私はなぜこれが働いたのが不思議ですか?私は明らかに動作しないlamba構文を使用して同様の問題がありますか? ConnectionStringFromKeyメソッドを使用しようとしています – Adam
これは 'FromAppSetting'が' ConfigurationManager.AppSettings ["key"];を使ってアクセスできる 'appSetting'キー値を必要とするために働きました。第2に、彼はリソース(すなわち接続文字列)からのキー「FnhDbString」の値を、直接失敗した 'FromAppSetting'メソッドに直接渡していました。問題のない親メソッドの単語に直接接続文字列を渡すだけです。 – Yogesh