N
narshe
I haven't come across an elegant way to do this yet, and would like to
know what other people have come up with.
There are two tables:
CREATE TABLE EmployeeStatus
(
pkId int not null primary key identity,
status varchar( 50 ) not null
)
CREATE TABLE Employees
(
pkId int not null primary key identity,
fkEmployeeStatusId int not null references EmployeeStatus( pkId ),
firstName varchar( 50 ),
lastName varchar( 50 ),
-- etc, etc, etc
)
The EmployeeStatus table would have values:
1 : Active
2 : Inactive
In the C# code there will be an Employee class that will reflect the
Employee table, with public properties for the data.
If I want to get a collection of Employees that are active or inactive,
I currently pass in the status value.
GetEmployees( 'Active' )
If the value in the db changes, then this won't work.
I've seen people make enums that have the same values as the primary
key id in the database.
GetEmployees( EmployeeStatus.Active )
But then the enum values need to match the database values, and we run
into the same issue.
I'd like to find a way to get the values, have it be strongly typed,
and not depend on any database values.
Is this possible?
Thanks.
-Josh
know what other people have come up with.
There are two tables:
CREATE TABLE EmployeeStatus
(
pkId int not null primary key identity,
status varchar( 50 ) not null
)
CREATE TABLE Employees
(
pkId int not null primary key identity,
fkEmployeeStatusId int not null references EmployeeStatus( pkId ),
firstName varchar( 50 ),
lastName varchar( 50 ),
-- etc, etc, etc
)
The EmployeeStatus table would have values:
1 : Active
2 : Inactive
In the C# code there will be an Employee class that will reflect the
Employee table, with public properties for the data.
If I want to get a collection of Employees that are active or inactive,
I currently pass in the status value.
GetEmployees( 'Active' )
If the value in the db changes, then this won't work.
I've seen people make enums that have the same values as the primary
key id in the database.
GetEmployees( EmployeeStatus.Active )
But then the enum values need to match the database values, and we run
into the same issue.
I'd like to find a way to get the values, have it be strongly typed,
and not depend on any database values.
Is this possible?
Thanks.
-Josh