Reputation: 127
This is the error i am getting during running the application.Could not load type nhibernate.Mssql2012.I m using sqlserver 2012 ,visual studio 2015
strong text Web config:
<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>
Database.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);
}
}
}
Upvotes: 1
Views: 3335
Reputation: 123901
Check the doc:
This is a snippet of the example configuration:
<!-- properties -->
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Server=localhost;...</property>
<property name="dialect">NHibernate.Dialect.MsSql2012Dialect</property>
The difference is in casing:
// current and wrong
<property name="dialect">Nhibernate.Dialect.MsSql2012Dialect</property>
// NHibernate, not Nhi...
<property name="dialect">NHibernate.Dialect.MsSql2012Dialect</property>
Upvotes: 2