0

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               emerg@contact.com   555-2020        John Adams      6548
2               emerg@harvard.edu   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();
Mike
  • 135
  • 2
  • 10
  • For CustomField, you could setup enums. https://msdn.microsoft.com/en-us/data/hh859576.aspx – Steve Greene May 19 '15 at 03:24
  • Interesting thought. You mean for the Field name? And then use some conditional logic when pulling it in? I feel like that would be less efficient as I'd be pulling in the whole table when I really only need a subset of it. – Mike May 19 '15 at 13:19

0 Answers0