Ok,

I've created a new Driver (SqlClient2008Driver that inherits from
SqlClientDriver) and a new IUserType (NhTimeSpan) and everything using
the time(x) db field works OK as well.

Code to SqlClient2008Driver: http://pastebin.com/T23x0iqY
Code to the IUserType: http://pastebin.com/H0fj8kQA

I can't use the core TimeAsTimeSpanType because it sets a DateTime
value (as required for the .net bug) instead of the correct TimeSpan
value in the Set(IDbCommand st, object value, int index) method.

With these files, no modification to the nh core is necessary (but I
still think that a proper workaround in the nh core would be
better.... as of right now, people using the nh core SqlClientDriver
and TimeAsTimeSpanType would be able to save/retrieve time(x) fields
but not query them)


On Jun 22, 5:11 pm, Fabio Maulo <[email protected]> wrote:
> The source where apply the workaround is a specific drive and not DriverBase
> (you can inherit from SqlClientDriver).
>
>
>
>
>
> On Tue, Jun 22, 2010 at 7:07 PM, Fabio Maulo <[email protected]> wrote:
> > The place for issues and patchs is
> >http://216.121.112.228/browse/NH
>
> > On Tue, Jun 22, 2010 at 7:02 PM, Victor H. Maksimenko <
> > [email protected]> wrote:
>
> >> Hello all,
>
> >> I've been using nhibernate trunk for a while without problems so far.
>
> >> Two issues that I've found so far are:
>
> >> 1) When trying to serialize the configuration (using a method similar
> >> to
> >>http://nhforge.org/blogs/nhibernate/archive/2009/03/13/an-improvement...
> >> ) and one of the property mappings is using the 'ReadOnlyAccessor' it
> >> throws because that class is not marked as Serializable... I've posted
> >> a patch here:http://pastebin.com/Emquf8Jgthat adds the serializable
> >> attribute to the ReadOnlyAccesor and the private NoopSetter class, and
> >> with that, the configuration gets serialized without problems.
>
> >> 2) With Sql Server 2008, (using the 2008 dialect), mapping a TimeSpan
> >> property with TimeAsTimeSpan (with the respective time(x) column in
> >> the db) works well just for saving/retrieving the value, but as soon
> >> as I try to query using that field (I've tried using QueryOver<> /
> >> Criteria, ex: .Where(x => x.TimeSpanProperty == TimeSpan.FromDays(1))
> >> or >=, <=, etc, I get db errors like 'time and datetime are
> >> incompatible in the greater than or equal to operator.', etc...) the
> >> problem is a bug in the .net System.Data.SqlClient.SqlParameter
> >> DbType setter (that calls an internal
> >> MetaType.GetMetaTypeFromDbType(value);) that sets the SqlDbType to
> >> DateTime instead of time... (you can read more about this bug - and
> >> it's confirmation - on
>
> >>http://connect.microsoft.com/VisualStudio/feedback/details/381934/sql...
> >> )
>
> >> I wrote a workaround that 'works for me', you can find the patch here
> >> (warning: it's as hackish as it can be):http://pastebin.com/S6Tr6Mg0
>
> >> I think it'd be better to set the dbParam.Size in the
> >> SqlClientDriver.cs -> SetDefaultParameterSize or SetParameterSizes
> >> methods... etc...
>
> >> It's an ugly workaround but it allows me to save/retrieve & query
> >> using that field without problems...
>
> >> I don't know if the NH team is willing to put a workaround in the nh
> >> code for that .net bug, or maybe should I try using a IUserType that
> >> forces the SqlDbType to Time in the NullSafeSet method...
>
> >> Opinions?
>
> >> Thanks
>
> > --
> > Fabio Maulo
>
> --
> Fabio Maulo

Reply via email to