If I use the DbCommand object I have no problems to use a GUID as parameter. The following code works:
DatabaseHelper.DbCommand.CommandText = "SELECT COUNT(*) FROM REPERTOIRE WHERE REPERTOIREGUID = @REPERTOIREGUID";
DatabaseHelper.DbCommand.CommandType = System.Data.CommandType.Text;
FbParameter parameter = new FbParameter("@REPERTOIREGUID", FbDbType.Guid);
parameter.Direction = ParameterDirection.Input;
parameter.Value = gidRepertoire;
DatabaseHelper.DbCommand.Parameters.Add(parameter);
return (Convert.ToInt16(DatabaseHelper.DbCommand.ExecuteScalar())>0);
However, doing more or less the same with the NHibernate native method "find" fails. The following code is NOT working:
IList repertoires = DatabaseHelper.Session.Find("FROM Repertoire WHERE RepertoireGUID = ?", gidRepertoire, TypeFactory.GetGuidType());
==> System.InvalidCastException
Source: FirebirdSql.Data.Firebird
at FirebirdSql.Data.Firebird.FbCommand.UpdateParameterValues()
at FirebirdSql.Data.Firebird.FbCommand.ExecuteCommand(CommandBehavior behavior, Boolean returnsSet)
at FirebirdSql.Data.Firebird.FbCommand.ExecuteReader(CommandBehavior behavior)
at FirebirdSql.Data.Firebird.FbCommand.ExecuteReader()
at FirebirdSql.Data.Firebird.FbCommand.System.Data.IDbCommand.ExecuteReader()
...
Like I said, this problem only occurs if I try to use char(16) with charset OCTETS instead of char(36) with default charset as the field to store my GUIDs in Firebird embedded. I would of course prefer the shorter version.
In the XML mapping file I've tried to declare the column RepertoireGUID as type "Guid", "String" and "Char", but without any luck.
Maybe it is a problem of Nhibernate as the firebird OCTETS support is not available for long time? It's still strange that the GUID is correctly converted in "DbCommand", but not in "Find".
Stefan
|