c# - Fluent NHibernate cascade delete problem -


i'm having problem fluent nhibernate cascade delete. i'm sure i'm doing wrong because isn't working.

here objects:

public class parent {     public int id { get; set; }     public ilist<sequencedchild> sequencedchildren { get; set; } }  public class sequencedchild  {     public int id { get; set; }     public int parentid { get; set; }     public int childid { get; set; }     public int sequence { get; set; } }  public class child  {     public int id { get; set; } } 

and here mapping:

hasmany(m => m.sequencedchildren).inverse().cascade.delete(); 

so have parent sequenced children , want update parent have no children. when update no sequenced children on parent expect in sequencedchild table records have id of parent deleted. reason nhibernate trying update parentid of records null - fails parentid not null. edit: i'm expecting child object unaffected (which behaving correctly).

i had @ few questions , suggest use of inverse doing this. doing wrong?

so managed find solution turned out have multiple steps:

  1. as james pointed out in comment parentid/childid should parent/child references not ids (+1 that)
  2. sequencedchild needs have explicit map sets cascade none
  3. when doing update, don't overwrite sequencedchild list. first clear add new items. (or clear if arent replacing items)
  4. the inverse() call not necessary
  5. the parentid field in db table should nullable because nhibernate insists on updating null before deletes it. (if knows way around leave comment)

Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -