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: