nHibernate Mapping with Oracle Varchar2 Data Types
Posted
by Blake Blackwell
on Stack Overflow
See other posts from Stack Overflow
or by Blake Blackwell
Published on 2010-04-12T20:45:00Z
Indexed on
2010/04/12
21:13 UTC
Read the original article
Hit count: 750
nhibernate
I am new to nHibernate and having some issues getting over the learning curve. My current question involves passing a string value as a parameter to a stored sproc. The error I get is:
Input string is not in correct format.
My mapping file looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="MyCompany.MyProject.Core"
namespace="MyCompany.MyProject.Core"
>
<class name="MyCompany.MyProject.Core.MyTable" table="My_Table" lazy="false">
<id name="Id" column="Id"></id>
<property name="Name" column="Name" />
</class>
<sql-query name="sp_GetTable" callable="true">
<query-param name="int_Id" type="int"/>
<query-param name="vch_MyId" type="String"/>
<return class="MyCompany.MyProject.Core.MyTable" />
call procedure MYPKG.MYPROC(:int_Id,:vch_MyId)
</sql-query>
</hibernate-mapping>
When I debug nHibernate it looks like it is not an actual string value, but instead just an object value. Not sure about that though...
EDIT:
Adding additional code for clarification:
UNIT Test
List<ProcedureParameter> parms = new List<ProcedureParameter>();
parms.Add( new ProcedureParameter { ParamName = "int_Id", ParamValue = 1} );
parms.Add( new ProcedureParameter { ParamName = "vch_MyId", ParamValue = "{D18BED07-84AB-494F-A94F-6F894E284227}" } );
try
{
IList<MyTable> myTables = _context.GetAllByID<MyTable>( "sp_GetTable", parms );
Assert.AreNotEqual( 0, myTables.Count );
}
catch( Exception ex )
{
throw ex;
}
Data Context Method
IQuery query = _session.GetNamedQuery( queryName );
foreach( ProcedureParameter parm in parms )
{
query.SetParameter(parm.ParamName, "'" + parm.ParamValue + "'");
}
return query.List<T>();
Come to think of it, it may have something to do with my DataContext method.
© Stack Overflow or respective owner