这是我在运行应用程序期间遇到的错误。无法加载类型 nhibernate.Mssql2012。我正在使用 sqlserver 2012,visual studio 2015
强文本网络配置:
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler,Nhibernate"/>
</configSections>
<connectionStrings>
<add name="MainDatabase" connectionString="Data Source=SARVESH\SQLEXPRESS;Database=SimpleBlog;Integrated Security=True"/>
</connectionStrings>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="dialect">Nhibernate.Dialect.MsSql2012Dialect</property>
<property name="connection.provider">Nhibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">Nhibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string_name">MainDatabase</property>
</session-factory>
</hibernate-configuration>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
数据库.cs
namespace simpleblog
{
public static class Database
{
private const string SESSION_KEY = "simpleblog.database.sessionkey";
private static ISessionFactory _sessionFactory;
public static ISession session
{
get { return (ISession)HttpContext.Current.Items[SESSION_KEY]; }
}
public static void Configure()
{
var config = new Configuration();
//configure the connection strings
config.Configure();
//add our mappings
var mapper = new ModelMapper();
mapper.AddMapping<UserMap>();
config.AddMapping(mapper.CompileMappingForAllExplicitlyAddedEntities());
//create session factory
_sessionFactory = config.BuildSessionFactory();
}
public static void OpenSession()
{
HttpContext.Current.Items[SESSION_KEY]= _sessionFactory.OpenSession();
}
public static void CloseSession()
{
var session = HttpContext.Current.Items[SESSION_KEY] as ISession;
if (session != null)
session.Close();
HttpContext.Current.Items.Remove(SESSION_KEY);
}
}
}