We have an app using NHibernate to connect to an Oracle database. I have been tasked with converting the Oracle DB to a SQL Server DB in such a way that switching between the DBs is as simple as changing the NHibernate drivers. In my Oracle DB I have a column defined as TIMESTAMP(6) WITH TIME ZONE. This column has been converted to a SQL Server datetimeoffset(6) data type. The mapping in my NHibernate hbm.xml file looks like this:
<property name="checkoutDate" type="DateTime">
<column name="CHECKOUT_DATE" sql-type="TIMESTAMP(6) WITH TIME ZONE" not-null="false" />
</property>
With this mapping I am able to insert a date into the table that shows up like this when I run a query in SSMS: 2018-05-24 10:48:17.000000 +00:00. However, when I try to query this table I get an two exceptions saying:
FormatException: Input string '5/24/2018 10:48:17 +00:00' was not in the correct format.
and
InvalidCastException: Unable to cast object of type 'System.DateTimeOffset' to type 'System.IConvertible'.
Does anyone know a way to have NHibernate recognize the format of the datetimeoffset column without changing the sql-type in the mapping? Or is there a sql-type that I can use in the mapping that will work for both the Oracle and SQL Server column types?