2011-10-06 110 views
0

我有麻煩設置流利的NHibernate的HasMany收集。流利NHibernate的HasMany收集不填充

我已經將代碼設置爲如下,我通過Linq IQueryable調用它。 在SQL事件探查器中,我可以看到正確調用的SQL,但Store.Staff集合始終爲空。

public class Store 
    { 
     public virtual IList<Employee> Staff { get; set; } 

     public virtual void AddEmployee(Employee Employee) 
     { 
      Employee.Store = this; 
      if(Staff == null) 
       Staff = new List<Employee>(); 
      Staff.Add(Employee); 
     } 


    public class StoreMap : ClassMap<Store> 
    { 
     public StoreMap() 
     { 
      Id(x => x.StoreId) 
       .GeneratedBy.Identity(); 

      HasMany(x => x.Staff) 
        .Inverse() 
        .Cascade.All();    
     ... 
     } 
    } 


    public bool Create(Store entity) 
    { 
     var stores = _readRepository.Query<Store>() 
      .Where(x => x.StoreId == entity.StoreId) 
      .Fetch(x => x.Staff) 
      .ToList(); 



select store0_.StoreId, 
     staff2_.SurgeryId, 
     staff2_.StoreId 
from dbo.[Store] store0_ 
     left outer join dbo.[Employee] staff2_ 
     on store0_.StoreId = staff2_.StoreId 
where store0_.StoreId = 1 /* @p0 */ 

感謝您的任何幫助。

回答

0

我混淆了框架的兩個部分。我正在使用Linq檢索數據,無法加載。 而不是使用Linq,我現在使用NHibernate.Session.QueryOver。

0

不知道這是問題,但您應該使用FetchMany來加載收藏,而不是Fetch。

相關問題