2013-08-24 76 views
1

我有一個scenerio,我正在保存一個對象的圖形,我需要在以後的另一個進程中檢索它。數據處理的簡單情況確實如此。nhibernate返回一個空的集合

問題是,在成功保存對象及其關聯集合(如輸出插入語句所示)後,同一對象的後續查詢將爲其關聯集合返回一個空集合。我甚至在此之前稱之爲Flush()。奇怪的是,關閉並重新打開應用程序會使其返回填充的集合。

我有這個映射約會類

<set name="workhours" inverse="true" cascade="all" lazy="true"> 
    <key> 
    <column name="person" /> 
    </key> 
    <one-to-many class="workhour" /> 
</set> 

這裏是進行數據檢索代碼

Method1() 
{ 
DataAccessManager.StartOperation(); 
     IEnumerable<Entity> q = GetQueryProvider(); 
     if (total > 0) 
     { 
      q = q.Skip(startIndex).Take(total); 
     } 
     totalfound = q.Count(); 
     IList<Entity> list = q.ToList(); 
     DataAccessManager.EndOperation(); 
     return list; 
} 
protected override IEnumerable<Entity> GetQueryProvider() 
    { 
     return DataAccessManager.GetQueryProvider<Appointment>(); 
    } 

,這對於節省

 if (this.Patient.Appointments== null) 
      this.Patient.Appointments= new Iesi.Collections.Generic.HashedSet<Appointment>(); 
     this.Patient.Appointments.Add(this); 

     if (this.Doctor.Appointments== null) 
      this.Doctor.Appointments= new Iesi.Collections.Generic.HashedSet<Appointment>(); 
     this.Doctor.Appoint.Add(this); 
     Entity ent = base.Save(); 
     return ent; 

     //the base call: 
     DataAccessManager.StartOperation(); 

     try 
     { 
      Entity t = DataAccessManager.Save<Entity>(this); 
      DataAccessManager.EndOperation(); 
      return t; 
     } 
     catch (NHibernate.HibernateException ex) 
     { 
      //handling   } 

//the Data Access save method 

public T Save<T>(T t) where T : Entity 
    { 

     try 
     { 

      CurrentSession.SaveOrUpdate(t); 

      return t; 
    } 
///exception handling and stuff 
    } 

我結束與會話Commit()和Disconnect()。

回答

0

沒關係,我沒有在保存之前設置關聯。