ef code first - EF codefirst delete all child objects in a many-many scenario? -


how delete child objects in in many many scenario? example, i'd delete roles belonging user.

i'm using ef code first.

first must select roles , remove user instance roles collection. save

var usersroles = user.roles.tolist();  usersroles.foreach(role => user.roles.remove(role));  context.savechanges();  // add new roles user 

ps. code may not exact, logic should use acomplish this.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -