我正在使用 FluentNHibernate 3.2,我有一个复杂的实体,我想初始化一个实体,并初始化所有代理。Session is closed!
我已经使用了 NHibernateUtil.Initialize 并且对于所有代理我都不起作用。
这是我的映射:
internal sealed class CityMap : ClassMap<City> {
public CityMap() {
Id(x => x.Id).GeneratedBy.Identity().Column("Id");
Map(x => x.Name, "Name");
Map(x => x.AlterName, "AlterName");
Map(x => x.ZipCode, "ZipCode5");
HasMany(x => x.Streets)
.LazyLoad()
.ExtraLazyLoad()
.KeyColumn("GovId")
.Cascade.All();
Table("Cities");
}
}
internal sealed class StreetMap : ClassMap<Street> {
public StreetMap() {
Id(x => x.Id).GeneratedBy.Identity().Column("Id");
Map(x => x.Name, "Name");
Map(x => x.AlterName, "AlterName");
References(x => x.City).LazyLoad().Column("GovId");
Table("Streets");
}
}
Here is my invocation:
using (UnitOfWork.Start()) {
// i get whole results until i need a Streets property
var source =_citiesRepository.Query.SingleOrDefault(c => c.Name.Contains(query));
// here I've tried to use NHibernateUtil.Initialize like so...
NHibernateUtil.Initialize(source); // <== here
}
当我尝试获取一些 Streets 时,我收到了Exception
that Session is closed!
,应该如何解决这个问题?
我不想禁用延迟加载...