How can I implement the User Type, able to handle guids from Oracle and MS SQL (raw16 and uniqueidentifier both). Target is to get xml-mapping and persistent classes, applicable to DBses.
my implementation (fails cause of "wrong column count") :
Code:
public class MyGuid : IUserType
{
#region .акр.т.е атр..ут.
private static readonly SqlType[] _sqlTypes = { SqlTypeFactory.Guid, SqlTypeFactory. GetBinary(16) };
private System.Guid? _value;
#endregion
...
public object NullSafeGet(
IDataReader resultSet,
string[] names,
object owner)
{
int index = resultSet.GetOrdinal(names[0]);
if (resultSet.IsDBNull(index))
{
return null;
}
try
{
_value = (System.Guid?)resultSet.GetValue(index);
}
catch
{
_value = new System.Guid?(new Guid((byte[])resultSet.GetValue(index)));
}
return _value;
}
public void NullSafeSet(IDbCommand statement,
object value,
int index)
{
if (value == null)
{
((IDbDataParameter)statement.Parameters[index]).Value = DBNull.Value;
}
else
{
System.Guid? guid = (System.Guid?)value;
((IDbDataParameter)statement.Parameters[index]).Value = value;
}
}
...
xml-mapping, f.example:
Code:
<class name="BusinessLayer.Classes.PERSON, BusinessLayer" table="PERSON">
<id name="Id" type="BusinessLayer.MyGuid, BusinessLayer">
<column name="OBJECTID" not-null="true" unique="true" index="PK_PERSON"/>
<generator class="BusinessLayer.GuidRawGenerator,BusinessLayer" />
<!--<generator class="native" />-->
</id>
Help, pls.