I am having an issue with NHibernate not deleting rows from the database. Nhibernate is saving and updating to the same database without issue.
After running SQL profiler it appears that there is no delete SQL being sent to the database - which makes me think it's a configuration issue but nothing is standing out to me...
Config
Nhibernate version : 3.3.1.4000 FluentNHibernate Version : 1.3.0.733 SQL Server Version : 2008R2
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.connection_string_name">IntermediateDatabase</property>
<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="show_sql">true</property>
<property name="connection.release_mode">auto</property>
<property name="adonet.batch_size">500</property>
<!-- Mapping assemblies -->
<!-- Can't map it for Fluent NHibernate here; instead, load the mapping assembly in Global.asax.cs.
If you're still using HBMs, you can use the mapping here or pass the assembly via Global.asax.cs
as well, just like you can do with the Fluent NHibernate assembly(s). -->
</session-factory>
</hibernate-configuration>
Thanks
Based on the information from your comment... It seems that your working method is like:
UPDATE
public T SaveOrUpdate(T entity)
{
using (Session)
{
using (TransactionScope scope = new TransactionScope())
{
Session.SaveOrUpdate(entity); scope.Complete();
}
return entity;
}
}
And this is absolutely correct... because your session FlushMode would most likely be:
session.FlushMode = FlushMode.Commit;
Pleae see more details here: Nhibernate Flush works commit doesn't
DELETE
But the poor sister Delete() is not fully supported as mighty Update()
public void Delete(T entity)
{
using (Session)
{
this.Session.Delete(entity);
}
}
So, while even for Delete() the session FlushMode is still hooked on a transaction commit ... there is no transaction. And that's for sure (well most likely) the real reason (as suspected)
Summary, treat both, Update and Delete as the twins... and give them the same care - i.e. transaction
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With