NHibernate Tour (17): Explore the use of stored procedures in NHibernate (next)

Source: Internet
Author: User
Tags scalar

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.