Tarique Sultan

Tarique Sultan

  • 1.5k
  • 219
  • 14.1k

How to Update and Delete related entities of an Object by EF

Mar 20 2018 10:06 PM
Let's suppose we have table called "EmployeeMaster" in our database and four sub-table like "Qualification", "TechnicalSkills", "BankDetails" and "EmploymentHistory".
They have foreign key relationship with "EmployeeMaster" table.
 
So i want to know, how to update and delete related Entities! means in "EmployeeMaster" table we have "List Collection" which are listed below.
  1. List technicalList{get;set;}  
  2. List qualificationList {get;set;}  
  3. List bankDetailsList {get;set;}  
  4. List employmentHistoryList {get;set;}  
when i pass "EmployeeMaster table object to update and delete methods in EF" then related entities of type listed above also be updated and deleted if i marked their object "Added" "Modifed" and "Deleted" in "EmployeeMaster" table related entities and this system of updating, adding or modifying related entites must be in generic form.
 
Right now! to make this done, we are using one repository per class and we are using database first approach and with two entities database entities and our custom model entities same as database entities and we are using Automapper.dll to map them together.
 
Kindly help to get this done using generic repository pattern system but keep in mind,
I want my Update Delete and Add method to Update, Delete and Add related entities.

Answers (1)