Hello Kumar,
I have never used fluent NHibernate, but I can show you how to achieve what
you want using NHibernate mappings.
The NHIbernate mapping for selecting and inserting should be something like:
<class name="Employee">
<id name="EmployeeId">
<generator class="native" />
</id>
<property name="EmployeeName" />
<property name="Salary" />
<loader query-ref="GetEmployeeDetails" />
<sql-insert>
DECLARE @emp_id int
EXEC sp_InsertEmployee @emp_name = ?, @salary = ?, @emp_id = @emp_id
OUTPUT
SELECT @emp_id
</sql-insert>
</class>
<sql-query name="GetEmployeeDetails">
<return alias="e" class="Employee">
<return-property name="EmployeeId" column="EmpId" />
<return-property name="EmployeeName" column="EmpName" />
<return-property name="Salary" column="Salary" />
</return>
EXEC sp_EmployeeDetails ?
</sql-query>
If you are able to use direct selects from the table or table functions,
you can make your life a lot easier by using a mapping like the following:
<class name="Employee">
<id name="EmployeeId" column="EmpId">
<generator class="native" />
</id>
<property name="EmployeeName" column="EmpName" />
<property name="Salary" />
<loader query-ref="GetEmployeeDetails" />
<sql-insert>
DECLARE @emp_id int
EXEC sp_InsertEmployee @emp_name = ?, @salary = ?, @emp_id = @emp_id
OUTPUT
SELECT @emp_id
</sql-insert>
</class>
<sql-query name="GetEmployeeDetails">
<return alias="e" class="Employee" />
SELECT {e.*} FROM fnEmployeeById(?) -- example using table function
</sql-query>
Hope that helps,
Gerke.
On Thursday, 12 September 2013 16:28:36 UTC+2, Kumar Jalli wrote:
> Hi,
>
> i want sample code to map the stored procedure return columns with the
> entity properties
>
> suppose i have an entity class
>
>
> Public Class Employee
> public Property EmployeeId as Integerpublic Property EmployeeName as
> stringpublic Property Salary as double
> End Class
>
>
>
> and the stored procedure in sql server
>
> suppose table is
> EmployeeDetails
>
> columns are
> EmpId int,
> EmpName nvarchar(50),
> Salary money
>
> and the procedure is
>
>
> create procedure sp_EmployeeDetails
> @EmpId as intasbegin
> Select * from EmployeeDetails where EmpId=@EmpId
> end
>
>
>
> so the class properties and the procedure return columns are not same how
> to map this using fluent in vb.code
>
>
> actually we are mapping the columns but both class properties and the
> procedure return columns are same using hbm.xml
>
>
>
> <?xml version="1.0" encoding="utf-8" ?><hibernate-mapping
> xmlns="urn:nhibernate-mapping-2.2"
> assembly="MyApplication" namespace="MyApplication">
>
> <sql-query name="GetEmployeeDetails" callable="true">
>
>
> <!-- Parameters -->
> <query-param name="EmpId" type="string"/>
>
>
> <!--Return values-->
> <return-scalar column="EmpId" type="integer"/>
> <return-scalar column="EmpName" type="string"/>
> <return-scalar column="Salary" type="double"/>
>
> { execute sp_EmployeeDetails(@EmpId)}
>
> </sql-query></hibernate-mapping>
>
>
>
> it is possible to get the data if the entity properties are
> EmpId,EmpName,Salary
>
> and how can we get the stored procedure output parameter value
>
> please help....
>
> Thanks in advance....
>
--
---
You received this message because you are subscribed to the Google Groups
"nhibernate-development" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.