1

Till now I was deleting a single row by writing:

Role role = new Role();
role = context.Roles.SingleOfDefault(p => p.Rolename == rolename);
context.Roles.DeleteOnSubmit(role);
context.SubmitChanges();

Now I need to delete from Role Permission table all the Permission rules that he had, so I want with the specific RoleId to delete multiple rows from RolePermission table (RolePermission table includes RoleId column). Is there any similar way to do this?

L. Achilles
  • 123
  • 1
  • 2
  • 14

2 Answers2

3

You have the DeleteAllOnSubmit method:

context.RolePermission.DeleteAllOnSubmit(
           context.RolePermission .Where(p=> p.RoleId == role.RoleId));
Zein Makki
  • 29,485
  • 6
  • 52
  • 63
  • First of all, it seems that this query would delete multiple columns from Role table, I want to delete multiple rows from RolePermission table using roleid. And secondly, I 've tried this command but unfortunately, it doesn't work. Thank you though for your help! – L. Achilles Jun 29 '17 at 10:52
  • @L.Achilles fixed typo. – Zein Makki Jun 29 '17 at 10:52
  • @L.Achilles did you call save changes after it ? – Zein Makki Jun 29 '17 at 12:32
0

After searching enough on the internet I 've found the answer to my question and I 've found it in stackoverflow. You can find the link below of from the question and the correct answer: How to Delete multiple records in Linq to Entity?

L. Achilles
  • 123
  • 1
  • 2
  • 14