J
James E
I have a question about best practices of how to deal with lookup data from
my C# apps. On a couple of occasions I have come across a problem where I
have to automate inserting a record into a table that has a foreign key
constraint that is linked to a lookup table. E.g. Take the following
database structure:
SQL-Server Database:
Table 1:
Name: CommunicationTypes
Columns: CommunicationID (Primary Key), Description
Table 2:
Name: Communications
Columns: CommunicationID (Primary Key), CommunicationTypeID (Foreign Key),
Sender, Recipient, etc.
...In this example, there is data such as the following in the
CommunicationTypes table:
CommunicationTypeID Description
------------------ ------------
1 Email
2 Letter
3 Phonecall
etc.....
My app needs to log details of communications, but in some cases,
auto-generates emails and letters. When this occurs I need to auto-insert a
record into the communications table. This means my app needs to know about
what the CommunicationTypeID is for the communication being 'auto-recorded'.
Should my app retrieve the CommunicationTypeID from the database by passing
the description? If the list is short, could I store the ID's in the config
file? Should I have a strongly typed class that has static methods to return
the ID from the lookup table? Other suggestions please!!
My question is, what is the best practice for situations like this, where:
a) You have a lookup table that will be added to over time
b) You need to insert a record into a table that has a foreign key related
to the lookup table, but the app needs to know the foreign key value without
the user selecting anything from a list.
Many thanks
JamesE
my C# apps. On a couple of occasions I have come across a problem where I
have to automate inserting a record into a table that has a foreign key
constraint that is linked to a lookup table. E.g. Take the following
database structure:
SQL-Server Database:
Table 1:
Name: CommunicationTypes
Columns: CommunicationID (Primary Key), Description
Table 2:
Name: Communications
Columns: CommunicationID (Primary Key), CommunicationTypeID (Foreign Key),
Sender, Recipient, etc.
...In this example, there is data such as the following in the
CommunicationTypes table:
CommunicationTypeID Description
------------------ ------------
1 Email
2 Letter
3 Phonecall
etc.....
My app needs to log details of communications, but in some cases,
auto-generates emails and letters. When this occurs I need to auto-insert a
record into the communications table. This means my app needs to know about
what the CommunicationTypeID is for the communication being 'auto-recorded'.
Should my app retrieve the CommunicationTypeID from the database by passing
the description? If the list is short, could I store the ID's in the config
file? Should I have a strongly typed class that has static methods to return
the ID from the lookup table? Other suggestions please!!
My question is, what is the best practice for situations like this, where:
a) You have a lookup table that will be added to over time
b) You need to insert a record into a table that has a foreign key related
to the lookup table, but the app needs to know the foreign key value without
the user selecting anything from a list.
Many thanks
JamesE