【发布时间】:2014-07-18 08:07:04
【问题描述】:
我遇到了 NHibernate 没有从数据库中删除行的问题。 Nhibernate 正在毫无问题地保存和更新到同一个数据库。
运行 SQL 分析器后,似乎没有删除 SQL 被发送到数据库 - 这让我认为这是一个配置问题,但对我来说没有什么特别突出...
配置
休眠版本:3.3.1.4000 FluentNHibernate 版本:1.3.0.733 SQL Server 版本: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>
谢谢
【问题讨论】:
-
据我所知,没有办法,如何将 NHibernate 配置为插入和更新但从不删除。我敢打赌,这个问题与应用程序级别有关。我最怀疑的是,DELETE 操作没有包含在事务中,或者它没有调用 session.Flus()... 你能显示你的删除代码吗?并解释它是如何包装在事务中的?
-
或者检查你没有
mutable=false但是如果你可以更新行那么我不怀疑...... -
能否也提供映射?
-
您确认数据被删除了吗?也许探查器没有显示代码,因为您正在通过 batch_size 进行批量更新。只需在提交 trx 后检查删除是否发生
-
嘿@RadimKöhler 从外观上看,删除没有包含在事务范围中: public void Delete(T entity) { using (Session) { this.Session.Delete(entity); } } 这可能是问题所在吗?更新为: public T SaveOrUpdate(T entity) { using (Session) { using (TransactionScope scope = new TransactionScope()) { Session.SaveOrUpdate(entity);范围。完成(); } 返回实体; } }
标签: c# sql nhibernate fluent-nhibernate