As you can see at below, there are a Lookup table for the enum values and I want to create a relationship between a table's enum values and LookupKey column of the Lookup table (instead of ID column of the Lookup table).
Lookup table:
ID | LookupType | LookupKey | LookupValue |
101 | Status | 0 | Passive |
106 | Gender | 1 | Male |
113 | Status | 1 | Active |
114 | Gender | 2 | Female |
118 | Status | 2 | Cancelled |
Main Table:
ID | Status | Gender | Name | ...
1 | 0 | 1 | John Smith | ...
2 | 1 | 2 | Christof Jahnsen | ...
3 | 2 | 1 | Alexi Tenesis | ...
4 | 0 | 2 | Jurgen Fechtner | ...
5 | 1 | 2 | Andreas Folk | ...
However, when using PK-FK relation and InverseProperty as on DataAnnotations - InverseProperty Attribute the relation is created with the ID column of the Lookup table and I cannot make the relation to the LookupKey column. Could you give an example how to achieve this?
We have a common lookup table here. It looks simlar to yours. LookupData has a primary key and a foreign key to LookupTypes which is equivalent to your enum and the value. We might also have some other simple fields like a flag or code which are identified in the LookupType metadata table. Then in out main table we might have "GenderLookupId" which points to the LookupData.Id field. The IDs themselves have no meaning and can be entered in any order. If you want gender 1 and 2 to have meaning, you should probably add another attribute for that (see surrogate keys).
Example with data:
LookupType
LookupData
Main Name Table
Classes:
}
}
LookupData Config:
Name Config: