Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i want sample code to map the stored procedure return columns with the entity properties

suppose i have an entity class

VB
Public Class Employee

public Property EmployeeId as Integer
public Property EmployeeName as string
public 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

SQL
create procedure sp_EmployeeDetails
@EmpId as int
as
begin

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
<?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>




Map File

VB
Imports FluentNHibernate.Mapping

Public Class EmployeeDetailsMap
    Inherits ClassMap(Of EmployeeDetails)


    Public Sub New()

        Id(Function(x) x.EmployeeId).Column("EmpId")
        Map(Function(x) x.EmployeeName).Column("EmpName")
        Map(Function(x) x.Salary).Column("Salary")
        Map(Function(x) x.DeptId).Column("DeptId")
    End Sub


End Class



Procedure code

VB
Dim employeeDetailsList As IList(Of EmployeeDetails) = Nothing
Dim sql As IQuery = session.GetNamedQuery("GetEmployeeDetails")
sql.SetInt32("EmployeeId", 1)
employeeDetailsList = sql.SetResultTransformer(Transform.Transformers.AliasToBean(Of EmployeeDetails)).List(Of EmployeeDetails)()





i am getting 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....
Posted
Updated 18-Sep-13 4:54am
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900