NHibernate,一列两种含义,正/负
我们有一个大型管理应用程序,我们对每个操作进行大量日志记录,例如,谁在什么时间做了什么。
然而,我们拥有越来越多的自动化系统,我们也希望将它们区分开来。
在我们所有的表中,我们都有一个名为 PerformedBy 的列,它是一个 int。这始终是对名为“Employees”的表的引用,该表有一个相应的名称。
然而我们现在希望有一些系统用户(例如在线支付服务器、在线预订等)。 我们当然可以在员工表中创建这些,但这似乎不正确,而且我们无法确定 ID(这是一个商业系统,因此我们有 200 个数据库需要更新。)
所以我真正想要的是要做的就是进行映射,以便如果 ID 为正,则它会映射到从数据库加载的员工。但是,如果它是否定的,我希望为每种类型的系统用户提供一些从 Employee one 派生的静态类。
比如:
class OnlineBooking : Employee
{
}
NHibernate 可以实现类似的功能吗?或者有人有另一个很好的解决方案吗? 我不想向所有具有日志的表添加额外的列。
We have a large management application and we do a lot of logging for every action, for instance, who did what and at what time.
However we have more and more automatic systems which we would like to differentiate as well.
In all of our tables we have a column called PerformedBy which is an int. This has always been a reference to a Table called Employees which then have a corresponding Name.
However we would now like to have some system users (for instance online payment server, online booking and so on).
We could of cause create these in the employees table however that seems incorrect and we wouldn't be certain of IDs (this is a commercial system, so we have 200 databases which would have to be updated.)
So what I would really like to do is make a mapping so that if an ID is positive it maps to an employee which is loaded from the database. However, if it is negative I would like to have some static classes which derive from Employee one for each type of system user.
Something like:
class OnlineBooking : Employee
{
}
Is something like this possible with NHibernate or does someone have another great solution ?
I would like not to add additional columns to ALL the tables that have logs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一列/两个含义是典型的数据库味道。您肯定想将其分成两列。
您将无法使用您描述的正/负方法启用外键约束。
http://www.agiledata.org/essays/databaseRefactoringSmells.html
这也将大大简化映射。添加列可能看起来需要大量额外工作,但从长远来看这是值得的。
One column / two meanings is a classic database smell. You definitely want to split this into two columns.
You will not be able to enable foreign key constraints with the positive / negative approach that you describe.
http://www.agiledata.org/essays/databaseRefactoringSmells.html
This will also greatly simplify mapping. Adding a column may seem like a lot of extra work, but it is worth it in the long run.