我在使用流畅的nhibernate删除行时遇到问题。如果我使用任何一个已注释掉的删除语句执行下面的方法,测试通过并说一切都很酷,但是当我检查数据库时,行仍然存在
[TestMethod]
public void DeleteAdhesiveWithoutCascade()
{
using (var session = sessionFactory.OpenSession())
{
//session.Delete(session.Load<Adhesive>(8));
//IQuery query = session.CreateQuery("FROM Adhesive WHERE ID = 8");
}
}
答案 0 :(得分:2)
尝试
[TestMethod]
public void DeleteAdhesiveWithoutCascade()
{
using (var session = sessionFactory.OpenSession())
using (var tx = session.BeginTransaction())
{
session.Delete(session.Load<Adhesive>(8));
//IQuery query = session.CreateQuery("FROM Adhesive WHERE ID = 8");
tx.Commit();
}
}
或
[TestMethod]
public void DeleteAdhesiveWithoutCascade()
{
using (var session = sessionFactory.OpenSession())
{
session.Delete(session.Load<Adhesive>(8));
//IQuery query = session.CreateQuery("FROM Adhesive WHERE ID = 8");
session.Flush();
}
}
答案 1 :(得分:1)
您应该打开一个交易。无论如何,在关闭session.Flush();
}