I have this code to delete contact from my database and I have got this error:No persister for: System.Int32
protected void Button1_Click(object sender, EventArgs e)
{
NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
config.AddAssembly("ContactDomain");
NHibernate.ISessionFactory factory = config.BuildSessionFactory();
NHibernate.ISession session = factory.OpenSession();
NHibernate.ITransaction transaction = session.BeginTransaction();
Contact contact = new Contact();
int contactid = 1;
session.Delete(contactid);
transaction.Commit();
session.Close();
}
I have this code for creating new contact and it’s working:
protected void btnSaveContact_Click(object sender, EventArgs e)
{
NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
config.AddAssembly("ContactDomain");
NHibernate.ISessionFactory factory = config.BuildSessionFactory();
NHibernate.ISession session = factory.OpenSession();
NHibernate.ITransaction transaction = session.BeginTransaction();
Contact contact = new Contact();
contact.FirstName = txtFirstName.Text;
contact.LastName = txtLastName.Text;
contact.Email = txtEmail.Text;
contact.Telephone = txtTelephone.Text;
session.Save(contact);
transaction.Commit();
session.Close();
}
You cannot delete an entity that is not saved! try:
update