我有以下代码。在 SQL Server 探查器中,我可以看到正在生成插入语句,但是没有插入实际记录。我只是不明白为什么会这样!
private ISessionFactory _sessionFactory;
private Configuration _configuration;
_configuration = new Configuration();
_configuration.Configure();
_configuration.AddAssembly(typeof(Task).Assembly);
_sessionFactory = _configuration.BuildSessionFactory();
using (var s = _sessionFactory.OpenSession())
using (var t = s.BeginTransaction(IsolationLevel.RepeatableRead))
{
var taskToSave = new Task
{
Class = "test class",
IsActive = true,
Namespace = "test namespace"
};
s.FlushMode = FlushMode.Commit;
s.Save(taskToSave);
t.Commit();
}
我的映射文件是这样的:
<class name="Task" table="Task">
<id name="Id" column="Id" unsaved-value="0" type="Int32">
<generator class ="identity"></generator>
</id>
<property name="IsActive" column="IsActive" not-null="true" type="Boolean" />
<property name="Namespace" column="Namespace" length="255" not-null="true" type="String" />
<property name="Class" column="Class" length="255" not-null="true" type="String" />
</class>
谢谢!顺便说一句,我正在使用 NHibernate-2.1.0.CR1。