The contents of this section
Introduced
Example analysis
Supplements
Conclusion
Introduced
Two, describes the use of the template provided by Mygeneration to create stored procedures and delete objects, create objects, update objects throughout the detailed process, this article describes how to use <sql-query> to do more, in the process of development, we not only use the stored procedures to check and modify objects, We can also want to execute arbitrary stored procedures, which is not limited to an object, a curd operation, how to do? Note: This is not the official authority of the information, so please refer to. If you have not yet learned nhibernate, please quickly link to the NHibernate Tour series article navigation.
Example analysis
Let me use a few examples to analyze using <sql-query> to execute stored procedures.
1. Return scalar
STEP1: Stored Procedures
CREATE PROCEDURE scalarSProcs
@number int
AS
BEGIN
SELECT @number as value, 'YJingLee' as name
END
This simulates the validation key/value pair and presses the query name. Return Yjinglee here.
STEP2: Mapping files
Use <sql-query> in the mapping file and define the name of the <sql-query> query, use the <return-scalar> element to specify the returned scalar value, and specify the alias and type of the field. When calling a stored procedure, you need a parameter, represented here by a named parameter, which opens Customer.hbm.xml to write the following code on the class element:
<sql-query name="ScalarSProcs">
<return-scalar column="value" type="int"/>
<return-scalar column="name" type="string"/>
exec scalarSProcs :number
</sql-query>