2009-07-14 50 views
0

我有以下代碼。在SQL Server分析器中,我可以看到正在生成的isnert語句,但是沒有插入實際的記錄。我無法弄清楚爲什麼會發生這種情況!nhibernate save()生成isnert語句,但沒有將實際記錄插入到db中

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。

+0

nhibernate版本? – 2009-07-14 02:24:24

回答

0

這是因爲我在代碼中的某個地方沒有意識到SchemaExport,並且代碼運行時SchemaExport創建了一個名爲dbo_owner_Task的新表,並將其插入dbo.Task的表中。

因此,當使用SchemaExport時很簡單!