FluentNHibernate Table DataTypes (different database vendors)
We have a situation where our production database is Firebird but would like to perform in-momory integration testing using SQLite. So far, the only problems we are encountering are differences in Data Types used by both databases.
As an example, when we map each domain object using FluentNHibernate we specify the column type whenever we need to explicitly specify it. We specify the CustomSqlType using a property from the following class;
public static class DATATYPES
{
public const string SMALLINT = "SMALLINT";
public const string BOOLEAN = "CHAR(5)";
public const string INTEGER = "INTEGER";
public const string DECIMAL_MONEY = "DECIMAL(18,4)";
开发者_开发问答 public const string DECIMAL_EXCHANGE_RATE = "DECIMAL(18,8)";
public const string DECIMAL_QUOTE_PRECISION = "DECIMAL(7,6)";
public const string DECIMAL_PERCENT = "DECIMAL(6,2)";
public const string BLOB_NULLABLE = "BLOB SUB_TYPE 1 SEGMENT SIZE 1 CHARACTER SET UTF8 COLLATE UTF8";
public const string BLOB_NOTNULL = "BLOB SUB_TYPE 1 SEGMENT SIZE 1 CHARACTER SET UTF8 NOT NULL COLLATE UTF8";
}
You can see from the class above that we map boolean values to a CHAR(5) column in the Firebird database. Now that we are trying to use the same mapping for SQLite we are encountering problems for BLOB and Boolean fields.
I'd like some advice on what we can do to overcome this shortcoming, without duplicating mapping code for different databases.
Of the top of my head, instead of explicitly defining the column type at each point you map a property to a field, could you instead consolidate this into a convention class that you would point to? This would be beneficial regardless (if every boolean is mapped to a CHAR(5), a convention would be better than invidually mapping it for every boolean property anyway). Then you could just switch conventions based upon the DB being used.
精彩评论