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?

2
  • Possible duplicate of linq to sql batch delete Commented Jun 29, 2017 at 10:47
  • Why do you instantiate a new Role and then just re-assign it? Commented Jun 29, 2017 at 10:58

2 Answers 2

3

You have the DeleteAllOnSubmit method:

context.RolePermission.DeleteAllOnSubmit(
           context.RolePermission .Where(p=> p.RoleId == role.RoleId));
Sign up to request clarification or add additional context in comments.

3 Comments

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 fixed typo.
@L.Achilles did you call save changes after it ?
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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.