So I resolved the SQL connection. Then when I run the following code in the code behind page, I get an error
"NHibernate.MappingException: Unknown entity class: QuickStart.User"
Code:
try
{
ISession session = NHibernateHelper.GetCurrentSession();
ITransaction tx = session.BeginTransaction();
User newuser = new User();
newuser.UserName = "Joseph Cool";
newuser.Password = "abc123";
newuser.EmailAddress = "
[email protected]";
newuser.LastLogon = DateTime.Now;
// Tell NHibernate that this object should be saved
//Here is where the error happens
session.Save(newuser);
// commit all of the changes to the DB and close the ISession
tx.Commit();
IList userList = session.CreateCriteria(typeof(User)).List();
GridView1.DataSource = userList;
GridView1.DataBind();
Label1.Text += userList.Count.ToString();
session.Close();
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}
I read in a blog that this is due to the hbm.xml file not being compiled as a resource. In my case, it is build in the class library as a resource. Here is my resource file:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="QuickStart.User, clsQuickStart" table="Users">
<id name="Id" column="LogonId" type="String" length="20">
<generator class="assigned" />
</id>
<property name="UserName" column="Name" type="String" length="40"/>
<property name="Password" type="String" length="20"/>
<property name="EmailAddress" type="String" length="40"/>
<property name="LastLogon" type="DateTime"/>
</class>
</hibernate-mapping>
What should I do?
Thank you