Hi.
I'm using the last version of NH (1.2.0 beta 2) and I've tried to compile an old implementation of IUserType and I'm getting the following error:
Quote:
Error 2 'Bremen.DTO.Types.MyTimeSpan' does not implement interface member 'NHibernate.IUserType.GetHashCode(object)' D:\Projetos\WingraphEx\VersaoDotNet\DTO\DTO\Types\MyTimeSpan.cs 11 18 DTO
So, to correct this, I've done the following:
Code:
public int GetHashCode(object o)
{
return 0;
}
I think it's not right, but it's just a test. After this, I've tried to compile again and got this error:
Quote:
Error 2 The type or namespace name 'TimeSqlType' does not exist in the namespace 'NHibernate.SqlTypes' (are you missing an assembly reference?) D:\Projetos\WingraphEx\VersaoDotNet\DTO\DTO\Types\MyTimeSpan.cs 23 66 DTO
So, my question is: where is the NHibernate.SqlTypes.TimeSqlType?
I need this type to map a TIME column from mySQL.
My full IUserType implementation is here:
Code:
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using NHibernate.SqlTypes;
using NHibernate.Type;
namespace Bremen.DTO.Types
{
public class MyTimeSpan : IUserType
{
/// <summary>
/// Public default constructor
/// </summary>
public MyTimeSpan() { }
/// <summary>
/// The SQL types for the columns mapped by this type.
/// </summary>
public SqlType[] SqlTypes
{
get { return new SqlType[] { new NHibernate.SqlTypes.TimeSqlType() }; }
}
/// <summary>
/// The type returned by <c>NullSafeGet()</c>
/// </summary>
public System.Type ReturnedType
{
get { return typeof(System.TimeSpan); }
}
/// <summary>
/// Compare two instances of the class mapped by this type for persistent "equality"
/// ie. equality of persistent state
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns></returns>
public bool Equals(object x, object y)
{
return TimeSpan.Equals(x, y);
}
/// <summary>
/// Retrieve an instance of the mapped class from a JDBC resultset.
/// Implementors should handle possibility of null values.
/// </summary>
/// <param name="rs">a IDataReader</param>
/// <param name="names">column names</param>
/// <param name="owner">the containing entity</param>
/// <returns></returns>
/// <exception cref="HibernateException">HibernateException</exception>
// /// <exception cref="SQLException">SQLException</exception>
public object NullSafeGet(IDataReader rs, string[] names, object owner)
{
int i = rs.GetOrdinal(names[0]);
if (rs.IsDBNull(i))
return null;
else
{
string t = rs[i].ToString();
return TimeSpan.Parse(t);
}
}
/// <summary>
/// Write an instance of the mapped class to a prepared statement.
/// Implementors should handle possibility of null values.
/// A multi-column type should be written to parameters starting from index.
/// </summary>
/// <param name="cmd">a IDbCommand</param>
/// <param name="value">the object to write</param>
/// <param name="index">command parameter index</param>
/// <exception cref="HibernateException">HibernateException</exception>
// /// <exception cref="SQLException">SQLException</exception>
public void NullSafeSet(IDbCommand cmd, object value, int index)
{
if (value == null)
((IDbDataParameter)cmd.Parameters[index]).Value = DBNull.Value;
else
{
IDataParameter parm = (IDataParameter)cmd.Parameters[index];
TimeSpan ts = (TimeSpan)value;
parm.Value = new TimeSpan(ts.Hours, ts.Minutes, ts.Seconds);
}
}
/// <summary>
/// Return a deep copy of the persistent state, stopping at entities and at collections.
/// </summary>
/// <param name="value">generally a collection element or entity field</param>
/// <returns>a copy</returns>
public object DeepCopy(object value)
{
return value;
}
/// <summary>
/// Are objects of this type mutable?
/// </summary>
public bool IsMutable
{
get { return true; }
}
public int GetHashCode(object o)
{
return 0;
}
}
}
Thanks!