Hi.I'm new in NHibernate and I'm disapointed in it.It makes my work easier but also complicates it.I need to call a stored procedure that doesn't return all columns from the table,only the columns that i need.
My stored procedure in MySql is:
Code:
CREATE DEFINER=`protocollo`@`%` PROCEDURE `SelectIn`(IN identifier INT)
BEGIN
if identifier = 0 then
Select Id,ReceivedDate,Recipient,Item,ProtocolNumber,FileName from entrata;
else
Select * from entrata where Id=identifier;
END IF;
END
and the .hbm file is:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Protocollo.Data" namespace="Protocollo.Data">
<class name="ProtocolIn" table="entrata" lazy="true">
<id name="Id" column="Id">
<generator class="native" />
</id>
<property name="ReceivedDate" column="ReceivedDate" type="string"/>
<property name="Recipient" column="Recipient" />
<property name="Item" column="Item"/>
<property name="ProtocolNumber" column="ProtocolNumber"/>
<property name="File" column="File" update="false" insert="false"/>
<property name="FileName" column="FileName"/>
</class>
<sql-query name="SelectAll" >
<return class="ProtocolIn">
<return-property name="Id" column="Id"/>
<return-property name="ReceivedDate" column="ReceivedDate"/>
<return-property name="Recipient" column="Recipient"/>
<return-property name="Item" column="Item"/>
<return-property name="ProtocolNumber" column="ProtocolNumber"/>
<return-property name="File" column="File"/>
<return-property name="FileName" column="FileName"/>
</return>
call SelectIn(?)
</sql-query>
</hibernate-mapping>
the C# code:
Code:
ISession session = NHibernateHelper.GetCurrentSession();
ITransaction tx = session.BeginTransaction();
IList<object> list = session.GetNamedQuery("SelectAll").SetParameter(0,0).List<object>();
tx.Commit();
session.Close();
NHibernateHelper.CloseSession();
return list;
when I send a specific Id to get all column it works fine when I put the identifier variable to 0 from store procedure in order to get only the columns that I need I get an error: "Could not find specified column in results".This error appears becouse I've specified the
File property in the .hbm file but I need this column for a specific identifier. How can avoid selecting the File column when identifier variable from stored procedure is 0.Please help.Give me some sugestions.
Thank you.
Have a nice day.[/i]