IsessionFactory问题
我在这一行收到经典的“对象引用未设置为对象的实例”错误
HttpContext.Items["ISession"] = Configure.GetSessionFactory().OpenSession();
如下所示,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;
namespace ForSale.Domain.NHibernate
{
public static class Configure
{
private static ISessionFactory _sessionFactory;
public static void Setup()
{
_sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(cs => cs.FromConnectionStringWithKey("Products")
).ShowSql())
.Mappings(m =>
m.FluentMappings.AddFromAssemblyOf<Product>().Conventions.AddFromAssemblyOf<Product>())
.BuildSessionFactory();
}
public static ISessionFactory GetSessionFactory()
{
return _sessionFactory;
}
}
}
我的configure.cs文件在webconfig中
<connectionStrings>
<add name="Products" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Products.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
我有连接字符串
使用在 VS2008 中构建的 appcode 文件夹中的 Products.mdf,
您知道为什么我可能会遇到此问题吗?
I am getting the classic "object reference not set to an instance of a object" error on this line
HttpContext.Items["ISession"] = Configure.GetSessionFactory().OpenSession();
My configure.cs file is as follows
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;
namespace ForSale.Domain.NHibernate
{
public static class Configure
{
private static ISessionFactory _sessionFactory;
public static void Setup()
{
_sessionFactory = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(cs => cs.FromConnectionStringWithKey("Products")
).ShowSql())
.Mappings(m =>
m.FluentMappings.AddFromAssemblyOf<Product>().Conventions.AddFromAssemblyOf<Product>())
.BuildSessionFactory();
}
public static ISessionFactory GetSessionFactory()
{
return _sessionFactory;
}
}
}
in the webconfig i have the connection string
<connectionStrings>
<add name="Products" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Products.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
With a the Products.mdf in the appcode folder which was build within VS2008
any ideas why i might be getting this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将方法 GetSessionFactory() 更改为以下内容:
You could change the method GetSessionFactory() to the following: