Using entity framework to detect changes in related table and action appropriate inserts and deletes

Posted by Kohan on Stack Overflow See other posts from Stack Overflow or by Kohan
Published on 2010-05-26T12:47:29Z Indexed on 2010/05/26 12:51 UTC
Read the original article Hit count: 245

Filed under:
|
|

Lets say i have a Person table, a Role table with a trel table PersonRoles linking them as many to many.

I create a new person and assign them to 2 roles (role 1, role 3).

I then want to edit this person; so i retrieve their data and bind their roles to a checkboxes. I change the values (Deselect role 1 and select role 2 instead) I then post this data back through a viewmodel.

Can i then get Entity Framework to update these roles for me, as in delete the entry in PersonRoles to role 1 and then add a new entry as role 2? Or do i have to do the logic for this myself?

Cheers, Kohan

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ