In my application there are two tables.
tblEvents
- EventID
- UserID
- Date
- EventType
tblEventTypes
- EventTypeID
- EventName
tblEvents contains a log of events that occurred in our application. One of the columns required when adding an event to the log is the event type. The event type must be the ID of an event type stored within tblEventTypes.
In my application using Entity Framework I created a function import for a stored procedure that adds events to tblEvents. Currently I pass in an integer for event type into the method created by the function import. This just seems unreadable to me as you have no idea what the integer means without looking at the database, finding the event types table, and seeing what event it was.
I would like to create an enum to represent event types. Is there a way to create a dynamic enum that is generated based on the data in tblEventTypes? Just like how EF generates entities based on tables in the database, I would like to generate an enum based off of a table and it’s current data. So adding an event type would be a matter of adding a row to tblEventTypes and then running an update in the EF designer or something that would automatically update my enum in the code.
You can’t use the EF designer for that, but you could use a T4 template to generate the enum.