0
我有两个类。两个类都具有相似的结构,因为它们都具有多对多的关系。但奇怪的是,第二堂课造成了LazyInitializationException
。我不知道为什么?两者都从中间表中提取数据,但第二类怎么会只产生错误?在一个类中引发NHibernate LazyInitializationException而不是另一个类
public class TaskMap : VersionedClassMap<Task>
{
public TaskMap()
{
Id(x => x.TaskId);
Map(x => x.Subject).Not.Nullable();
Map(x => x.StartDate).Nullable();
Map(x => x.DueDate).Nullable();
Map(x => x.DateCompleted).Nullable();
References(x => x.Status, "StatusId");
References(x => x.Priority, "PriorityId");
References(x => x.CreatedBy, "CreatedUserId");
HasManyToMany(x => x.Users)
.Access.ReadOnlyPropertyThroughCamelCaseField(Prefix.Underscore)
.Table("TaskUser")
.ParentKeyColumn("TaskId")
.ChildKeyColumn("UserId");
HasManyToMany(x => x.Categories)
.Access.ReadOnlyPropertyThroughCamelCaseField(Prefix.Underscore)
.Table("TaskCategory")
.ParentKeyColumn("TaskId")
.ChildKeyColumn("CategoryId");
}
}
和
public class LocationMap: VersionedClassMap<Location>
{
public LocationMap()
{
Id(x => x.LocationId);
Map(x => x.Name).Not.Nullable();
Map(x => x.Address).Nullable();
Map(x => x.City).Nullable();
Map(x => x.State).Nullable();
Map(x => x.Country).Nullable();
Map(x => x.Pincode).Nullable();
HasManyToMany(x => x.Departments)
.Access.ReadOnlyPropertyThroughCamelCaseField(Prefix.Underscore)
.Table("LocationDepartment")
.ParentKeyColumn("LocationId")
.ChildKeyColumn("DepartmentId"); //.Fetch.Join(); Adding this removes the error
}
}
编辑:
这里是link该项目。
我将在星期一到达办公室时共享我的整个解决方案。请帮我解决这个问题。 –
我已经添加了源代码。你能告诉我发生了什么吗? –
有很多代码。异常抛出在哪里?如何重现该问题? –