2010-08-31 56 views
1

我有三个映射如下:NHibernate的级联和逆

public MainChapterMap() 
{ 
    // other properties 

    HasMany(x => x.ClientSpecific).KeyColumn("MainChapterId"); 
} 

public MainChapterClientMap() 
{ 
    // other properties 

    References(x => x.MainChapter).Column("MainChapterId"); 
    HasMany(x => x.Details).KeyColumn("MainChapterClientId"); 
} 

public MainChapterClientDetailMap() 
{ 
    // other properties 

    References(x => x.MainChapterClient).Column("MainChapterClientId"); 
} 

MainChapter有许多客户特定的章节。客户特定的章节(MainChapterClient)有许多翻译(MainChapterClientDetail

的DELE规则应该如下:

  1. 当删除MainChapter
    • 删除MainChapterClient
    • 删除MainChapterClientDetail
  2. 当删除婷MainChapterClient
    • 不要删除MainChapter
    • 删除MainChapterClientDetail行(S)
  3. 当删除MainChapterClientDetail
    • 不要删除MainChapter
    • 做不删除MainChapterClientDetail行(s)

但是我不管我最终得到这个错误:

deleted object would be re-saved by cascade (remove deleted object from associations)[Entities.MainChapterClient#39]

我不知道如何设置我的瀑布了。任何帮助都比欢迎!

回答

1

你需要从两侧取出参考:

MainChapterClient.Details.Remove(instance); 
instance.MainChapterClient = null; 
+0

感谢它帮我。 – 2012-10-12 10:49:05