In a c#.net application I have a two classes as below
Employee
EmployeeId : int : Primary key
Name : string
Job
JobId : int : Primary key
Name : string
EmployeeId : int
In database (SQL Server) I have two tables to save data from those classes (Employee & Job)
(ID fields are auto increment fields so can have same no in both tables)
Now I need to implement a new feature to give users to add comments for Employees or for Jobs, So I need to create a single Comment class to share by both classes.
What is the best Class & Table Structure to implement this new feature.
I’d recommend a database design like which allows adding more comment types in the future without the need to modify your database.
Table Comment
Table CommentType
CommenteeIdwill referenceJoborEmployeeor any other table you’d need to comment in the future.CommentTypeIdwill referenceCommentTypewhere you can add types as needed.As for your class design it could look like this:
… as a basic idea. How and when your
Commentis loaded as part ofEmployeeorJobis depending on your method of accessing your database.