我在我的Web应用程序中使用NHibernate。到目前为止,我已经创建了以下hibernate映射对象类:
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() {
}
}
}
以下代码:
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);
来自班级NHibernateModule : IHttpModule
的构造函数。
这是我的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>
现在,类User
位于App_Code的Dao文件夹中,hbm.xml位于同一个Dao文件夹中,类NHibernateModule
位于App_Code的HttpModules文件夹中:
App_Code
|-------Dao
| |---User.cs
| |---NHibernateMapping.hbm.xml
|-------HttpModules
|---NHibernateModule.cs
当我运行我正在运行的应用程序时:
[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
任何信息都对我很有帮助。
感谢。
答案 0 :(得分:1)
您是否已将hbm.xml文件设置为嵌入资源?