views:

399

answers:

2

I have tables named Events and Log. The Events table comprises of ID, Event description and type. And, the Log contains LogID, EventID(refers to ID from Event table), and timstamp.

I am using Entities framework. While making an entry in the log table, i mention the event id as the number corresponding to the log event from the Event table. As i continue to use this logging across the app, it becomes cumbersome to remember the event id for the logged event. I would like to map these event ID as enums in my code and just use the enum for better usability.

Has anyone created enums using this approach? If so, please share your thoughts on the design for creating one.

A: 

Rather than creating ENUMS have you looked into representing them as navigation properties in your entity sets?

Graham
can you throw more light on this? an example or reference would be great!
pencilslate
In your initial description you said "The Events table comprises of ID, Event description and type. And, the Log contains LogID, EventID(refers to ID from Event table), and timstamp." I take this to mean you have a foreign key relation between the EventID column and the IDs in your events table. If this is the case EF1 will create navigation properties based on this relation if you generate your EDMX file from your DB. These navigation properties will allow you to perform lookups just like you would using a database. For example: logInstance.Event.ID would give you the corresponding event ID.
Graham
This msdn article provides a pretty good overview: http://msdn.microsoft.com/en-us/library/bb896321.aspx
Graham
Thanks Graham! I will look at it.
pencilslate
+1  A: 
Thorarin
Thorarin, my eventIDs are fixed eventhough the list might grow over a period of time. maybe, i am missing the point about using the global::. an example or reference would be great!
pencilslate
Doh, no wonder you were missing the point... I was thinking LINQ to SQL somehow rather than Entity Framework. I've updated my answer.
Thorarin
Let me check it out first.
pencilslate
@Thorarin: Sorry about the delayed response. I guess, i need to rename one of the 'EventType' as it's throwing ambiguity errors during build. I renamed the enum as EventTypeEnum to get past the error.
pencilslate
Alright.. here it is. The EventType:int is a reference to the table, EventType. With your enum solution, probably i won't even need the EventType table and instead have the column EventType in EventCalendar as non-referencing column. But, this would leave the possible values for eventype purely on the BL code. I am not sure, if it's a good design. On the other hand, retaining the EventType table on the DB and also defining Enum on the BL code results in two copies of event types list that are disconnected. I would go with maintaining both EventType table and enum for now.
pencilslate