简体   繁体   中英

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 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM