FluentNHibernate SQL Server 配置;连接字符串问题
这是我第一次尝试 Fluent NH。我将连接字符串存储在 Properties.Settings 中;
FnhDbString = Data Source=PC\SQLEXPRESS;Initial Catalog=FNHTest;Integrated Security=True
如果我使用 .FromAppSetting
配置 Fluent,则会出现异常:
ArgumentNullException
Value cannot be null. Parameter name: Data Source
如果我使用 .FromConnectionStringWithKey
配置 Fluent,则会出现异常:
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();
}
...
那么我在这里做错了什么..?
It's my first attempt on Fluent NH. I store the connection string in Properties.Settings;
FnhDbString = Data Source=PC\SQLEXPRESS;Initial Catalog=FNHTest;Integrated Security=True
If I configure Fluent with .FromAppSetting
I get exception:
ArgumentNullException
Value cannot be null. Parameter name: Data Source
If I configure Fluent with .FromConnectionStringWithKey
I get exception:
NullReferenceException
Object reference not set to an instance of an object.
The full method:
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();
}
...
So what am I doing wrong here..?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将此:更改
为:
Change this:
to this: