Mapping Entity Framework from Existing Database with Custom Field Structure

117 Views Asked by At

I'm using Entity Framework 6 with a Code First approach. We use a commercial, off the shelf software solution that I'm rolling up into our own custom application. In addition to having the basic tables for Employee, Salary, JobDetail where this is possible:

myEmployee.First " " + myEmployee.Last;
myEmployee.Salary.Where(x => x.SalaryEndDate == null).FirstOrDefault().Amount.ToString();

it also has a custom field configuration in the DB like this:

CustomField table:

GrpID   CstmFldID   CstmFldGrp  CstmFldName
1       1           Education   University
1       2           Education   Degree
1       3           Education   Major
2       1           Logistics   EmergencyEmail
2       2           Logistics   EmergencyPhone  
2       3           Logistics   EmergencyContact

CustomFieldData table:

CstmFldGrpID    CustomField1        CustomField2    CustomField3    EmployeeID
1               George Washington   Bachelors       Philosophy      6548
1               Harvard University  Masters         Business Mgt    4687
2               [email protected]   555-2020        John Adams      6548
2               [email protected]   555-0001        Paul Revere     4687

How would you go about mapping those custom fields into domain entities? For example, I'd want to be able to write:

myEmployee.Education.University.ToString(); 
myEmployee.Logistics.EmergencyPhone.ToString();
0

There are 0 best solutions below