wayne wrote:
I use lookup tables in my apps too. However for me, I almost always bind them to comboboxes. So you can bind the ID field to SelectedValue property, and the Text property to the country field. It was just as easy if not easier that way. Can you give an example of another way in which enums might be better? Maybe in the BL Layer?
This should actually be under architural section...
Binding the tables are not a problem - as that is a good solution to use in interfaces but in BL Code you don't have that luxery and often in your BL you need to know what the value of a certain field represents. What is PaymethodID 1?
Paymethods do not change that often so they are a good example of lookup values that could be enumerized.
For example Paymethods:
1. Credit Card
2. Debit Card
3. Cheque.
I use enums when i have to do a certain something when a payment transaction happens.
if Ordertransaction.paymentID = Paymethod.creditcard then
else
if Ordertransaction.PaymethodID = Paymethod.Debitcard then
endif
endif
If you did not have enums for PaymethodID then you would have had to hard code the value or you would have had to hard code the description and then lookup the Value part for the matching description.
I found it usefull to have enums for lookup table values that do not change that often - especially system settings like employee maritial status, titles, security groups ext.. but the choice of which lookuptables to enumerize must be made carefully. Seeing that you don't want to release a new version just because you added a new Bank Branch.
Thats what I was thinking for comparing values in the BL. I guess enums could be pretty nice for that.
I am using adapter. In my BL I have an EmployeeManager class, with a GetEmployee method that returns an employee entity. In my PL I required checking the employees role, which has a FK to the Role table. In my PL I didn't want to do
if(employee.Role = 1)
Sooo I wrote in my BL to fill the Role Entity as well. So now GetEmployee returns the employee, with the relation to Roles filled. So now I have something like this
if(employee.Role.Description == "administrator")
Using enums in this case would be nice if your forgot the different roles an employee could have. Plus autocomplete is nice
Also, not having to do the extra coding in the EmployeeManager class could have been avoided, as writing the extra code to fill a Role Entity in the EmployeeManager class gets confusing/messy as your relations get deeper and more complex.