On a system that ran on SQLCE, MSSQL, Oracle I used to just remap the
datatype in the MSSQL driver to allow storage of dates prior to 1753. So
something like:
public override void AdjustCommand(IDbCommand command)
{
foreach (IDbDataParameter parameter in command.Parameters)
{
if (parameter.DbType == DbType.DateTime)
{
parameter.DbType = DbType.DateTime2;
parameter.Size = 8;
}
}
}
NHibernate always felt it was almost, but not quite there with dates.
Richard
On Wed, Sep 10, 2014 at 4:54 PM, Oskar Berggren <[email protected]>
wrote:
> Hi,
>
> I'm trying to understand the best way (and any room for improvement) to
> handle timestamps with high resolution running over different database
> dialects.
>
> With todays NHibernate, what is the cleanest way to store timestamps with
> resolution at least 1ms that will work for both MSSQL and SQLite?
>
>
> This is the default for a .Net DateTime property:
> DateTimeType
> /// This only stores down to a second, so if you are looking for the most
> accurate
> /// date and time storage your provider can give you use the <see
> cref="TimestampType" />.
>
>
> DateTime2Type
> Uses DbType.DateTime2 and datetime2 on MS SQL Server. Fails for everything
> else it seems, so I cannot cleanly use it in mappings and have it run on
> MSSQL in production and SQLite in tests.
>
>
> TimestampType
> Is recommended by DateTimeType if an accuracy greater than 1 second is
> required and has the following documentation "stores it to the accuracy the
> database supports, and will default to the value of DateTime.Now if the
> value is null."
>
> The problem is that I'm not talking about a versioning property here - I
> _want_ null values to be stored as null so TimestampType doesn't fit.
> Because of this null-handling I think it's a bit strange that this type is
> recommended by DateTimeType for high resolution.
>
> Nowadays, the "stores it to the accuracy the database supports" is
> actually a lie, because it will round to 10ms on MS SQL Server instead of
> using the datetime2 type.
>
>
> /Oskar
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "nhibernate-development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
---
You received this message because you are subscribed to the Google Groups
"nhibernate-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.