I'm working on an application that will store "commands" in a database using NHibernate. Each command will have a set of arguments with it. For instance, the "sleep" command has a duration, and "set text" has a string value. All of these commands derive from the same Command
base type.
I'd like to allow additional commands to be added in the future with the smallest possible impact to the database. My initial reaction is to use the table-per-hierarchy pattern since the only schema modification required would be to add a column to the Command table.
I also considered using the TPH pattern but mapping generic columns instead of specific ones, and then convert them to the specific (strongly-typed) property values in the classes themselves (i.e. shadow the mapped, generic string properties with strongly-typed public properties). That way I wouldn't have to change the table at all if I had a number of columns equal to the most arguments any command could need. These seemed a little hacky in my mind though...
As a relative new-comer to database design and NHibernate usage, can someone point holes in these approaches, or suggest something better? I'm trying to avoid changing the schema (as much as possible) while allowing for future extension and a simple C# API.
Look into a BaseImmutableUserType<T> : IUserType
implementation, this would allow you to use the generic column.