向现有类添加新功能(C#)
发布时间:2020-12-16 01:48:03 所属栏目:百科 来源:网络整理
导读:在c#.net应用程序中,我有两个类,如下所示 Employee EmployeeId : int : Primary key Name : string Job JobId : int : Primary key Name : string EmployeeId : int 在数据库(SQL Server)中,我有两个表来保存这些类中的数据(Employee Job) (ID字段是自动增量
在c#.net应用程序中,我有两个类,如下所示
在数据库(SQL Server)中,我有两个表来保存这些类中的数据(Employee& Job) 现在我需要实现一个新功能,以便用户为Employees或Jobs添加注释,因此我需要创建一个由两个类共享的Comment类. 什么是最好的Class&表结构实现此新功能. 解决方法
我建议使用数据库设计,以便将来添加更多注释类型,而无需修改数据库.
表评论 Id (int,Primary Key) CommenteeId (int,not null) CommentTypeId (int,not null) Text (nvarchar(255)) 表CommentType Id (int,Primary Key) Name (nvarchar(50),not null) CommenteeId将引用您将来需要评论的工作或员工或任何其他表格. CommentTypeId将引用CommentType,您可以根据需要添加类型. 至于你的课程设计,它可能如下所示: public class Job { public List<Comment> Comments; public string Name { get; set; } } public class Employee { public List<Comment> Comments; public string Name { get; set; } } ……作为一个基本想法.如何以及何时将您的注释作为Employee或Job的一部分加载取决于您访问数据库的方法. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |