我有麻煩設置流利的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 */
感謝您的任何幫助。