开发者

NHibernate, one column two meanings, positive/negative

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开发者_StackOverflow社区 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜