I am using NHibernate in my web application. So far I have created this following hibernate mapping object class:
namespace Dao {
/// <summary>
/// Summary description for User
/// </summary>
public class User {
private int _id;
public int Id {
get {
return _id;
}
private set {
_id = value;
}
}
private string _name;
public string Name {
get {
return _name;
}
set {
_name = value;
}
}
public User() {
}
}
}
The following code:
Configuration configuration = new Configuration();
configuration.Configure();
configuration.SetProperty("connection.connection_string", WebConfigurationManager.ConnectionStrings["EMSConnectionString"].ConnectionString);
HbmSerializer.Default.Validate = true;
configuration.AddInputStream(HbmSerializer.Default.Serialize(Assembly.GetExecutingAssembly()));
configuration.AddDirectory(new DirectoryInfo(HttpContext.Current.Server.MapPath("~/App_Code/Dao")));
SessionFactory = configuration.BuildSessionFactory();
SchemaExport se = new SchemaExport(configuration);
se.Drop(false, true);
se.Create(false, true);
from the constructor of the class NHibernateModule : IHttpModule.
This is my hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Dao" assembly="Dao">
<class name="Dao.User" table="User">
<id name="Id" column="Id">
<generator class="native"/>
</id>
<property name="Name" column="Name" length="50"/>
</class>
Now the class User is in Dao folder of App_Code, the hbm.xml resides in the same Dao folder and the class NHibernateModule is in the HttpModules folder of App_Code:
App_Code
|-------Dao
| |---User.cs
| |---NHibernateMapping.hbm.xml
|-------HttpModules
|---NHibernateModule.cs
When I am running the application I am getting:
[MappingException: The following assembly contains no mapped classes: App_Code.qy81yxpd, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]
NHibernate.Mapping.Attributes.HbmSerializer.Serialize(Stream stream, Assembly assembly) +2855
NHibernate.Mapping.Attributes.HbmSerializer.Serialize(Assembly assembly) +132
HttpModules.NHibernateModule..cctor() in e:\EMS\App_Code\HttpModules\NHibernateModule.cs:26
Any information will be very helpful to me.
Thanks.
Have you set your hbm.xml file to be embedded resource?