我有两个对象通过映射表彼此具有多对多关系。虽然,当我尝试保存它时,我得到一个堆栈溢出异常。以下是映射的代码:
//EventMapping.cs
HasManyToMany(x => x.Performers).Table("EventPerformer").Inverse().Cascade.AllDeleteOrphan().LazyLoad().ParentKeyColumn("EventId").ChildKeyColumn("PerformerId");
//PerformerMapping.cs
HasManyToMany<Event>(x => x.Events).Table("EventPerformer").Inverse().Cascade.AllDeleteOrphan().LazyLoad().ParentKeyColumn("PerformerId").ChildKeyColumn("EventId");
当我将 performermapping.cs 更改为 Cascade.None() 时,我摆脱了异常,但是我的事件对象没有我与之关联的执行者。
//In a unit test, paraphrased
event.Performers.Add(performer); //Event
eventRepository.Save<Event>(event);
eventResult = eventRepository.GetById<Event>(event.id); //Event
eventResult.Performers[0]; //is null, should have performer in it
我应该如何正确地写这个?谢谢