Add more execution functions for SubSonic3.0 queries (SubSonic. Query. Select and stored procedures)

Source: Internet
Author: User

When using the SubSonic3.0 query function, we will find that we want to return the data we want through execution, and there is no related function, for example: SubSonic. query. the Select statement does not return DataSet, able, or other functions when you use a query statement. It is the same when you execute a stored procedure. It also lacks the function of returning the first column value of the first line, which is inconvenient, so I opened the source code of the plug-in and found that the execution interfaces of these functions exist, but these execution classes did not implement them, so I added them manually.

Open the SqlQuery. cs file in the SubSonic. Query folder in the plug-in, find the ExecuteScalar () function, and add the following code under this function:

/// <Summary> // execute the query and return the DataTable // </summary> /// <returns> </returns> public virtual DataTable ExecuteDataTable () {DataTable result; try {result = _ provider. executeDataSet (GetCommand ()). tables [0];} catch (Exception x) {InvalidOperationException ex = GenerateException (x); throw ex;} return result ;}

Because the Select class inherits the SqlQuery class, this function is implemented in the SqlQuery class, so the Select class naturally has this function.

For details, see:

Call example:

  

 

 

 

Open the StoredProcedure. cs file in the SubSonic. Schema folder in the plug-in, find the Execute () function, and add the following code under this function:

/// <Summary> /// executes the stored procedure and returns the value of the first column in the first row. /// </summary> public object ExecuteScalar () {return Provider. executeScalar (Command) ;}/// <summary> /// executes the stored procedure and returns the specified (generic) type /// </summary> /// <typeparam name = "T"> </typeparam> /// <returns> </returns> public T ExecuteSingle <T> () where T: new () {return Provider. executeSingle <T> (Command );}

For details, see:

  

 

Call example:

  

 

After the above Code is added, you can use the SubSonic3.0 plug-in source code again.

 

This article is original content. Keep the following information for reprinting.

As long as you want to learn and make progress together, if you are interested, you can add the Q group: SubSonic3.0 Learning Group (327360708) or Email to me (1654937 # qq.com ), I am very busy. If you have any questions, please leave a message first. Please forgive me for not replying in time.

For more questions about SubSonic3.0, refer to the blog:

 

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.