nhibernate - Fluent Mapping : using join-table and cascades -


having little trouble mapping following table setup currently:

               shop              [1]  [1]                              /       \           [n]       [n]    category-[m]---[n]-article 

the behaviour should following :
1 - when deleting shop, articles , categories should deleted
2 - when deleting category, related articles should unassigned not deleted
3 - when deleting article, related categories should unassigned not deleted

here's current mapping:

public class shopmap: classmap<shop> {     public shopmap()     {         this.table("shop");         id(x => x.id).column("id").generatedby.native();         map(x => x.name).column("name");          hasmany(x => x.categories).cascade.alldeleteorphan;         hasmany(x => x.articles).cascade.alldeleteorphan;     } }  public class categorymap: classmap<category> {     public categorymap()     {         this.table("category");         id(x => x.id).column("id").generatedby.native();         map(x => x.name).column("name");          references(x => x.shop);          hasmanytomany(x => x.articles).cascade.alldeleteorphan()                                     .table("article_category")                                     .childkeycolumn("article_id")                                     .parentkeycolumn("category_id")                                         .inverse();     } }  public class articlemap: classmap<article> {     public articlemap()     {         this.table("article");         id(x => x.id).column("id").generatedby.native();         map(x => x.name).column("name");          references(x => x.shop);          hasmanytomany(x => x.categories).cascade.all()                                     .table("article_category")                                     .parentkeycolumn("article_id")                                     .childkeycolumn("category_id");     } } 

when deleting category (session.delete()), nh tries delete related articles well. changing cascade-mode saveupdate fix this, leave entries in link table *article_category*. summing : cascade.saveupdate lazy, cascade.all eager.

i tried came mind in mappings, couldn't find correct way map (rather simple schema).

any ideas on how (fluently) map appreciated!

thanks in advance

sebi

the entries left in link table because category.articles defined inverse side of relationship. need remove category article.categories before deleting in order link record removed.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -