我有一个 UnitOfWork/Service 模式,我在将模型发送到视图之前使用 NHibernate 填充模型。出于某种原因,我仍然得到 YSOD,而且我不明白为什么对象集合尚未填充。
我的控制器方法如下所示:
public ActionResult PendingRegistrations()
{
var model = new PendingRegistrationsModel();
using (var u = GetUnitOfWork())
{
model.Registrations = u.UserRegistrations.GetRegistrationsPendingAdminApproval();
}
return View(model);
}
服务/工作单元如下所示:
public partial class NHUserRegistrationRepository : IUserRegistrationRepository
{
public IEnumerable<UserRegistration> GetRegistrationsPendingAdminApproval()
{
var r =
from UserRegistration ur in _Session.Query<UserRegistration>()
where ur.Status == AccountRegistrationStatus.PendingAdminReview
select ur;
NHibernateUtil.Initialize(r);
return r;
}
}
我究竟做错了什么?