2013年8月3日星期六

As SubSonic3.0 query (SubSonic.Query.Select and stored procedures)to add more executive function

 

using SubSonic3.0 inquiry function, you will find that we want to execute to return the desired data, cut no related features, such as: SubSonic.Query.Select, using the query does not return a DataSet or DataTable, etc. function, and execute a stored procedure is the same, but also the lack of a return to the first line of the first column value functions, inconvenient, so they looked open source plugin, discovered that in fact perform these functions interfaces exist, but that the Several implementation class does not implement them out, so I manually add a bit.

 

open plug-in SubSonic.Query folder SqlQuery.cs file, find the ExecuteScalar () function, in this function by adding the following code:

 
  
         /// <summary> 
/// 执行查询,返回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;
}
 
 Select class is inherited

because SqlQuery class, so in SqlQuery class implements this function, then Select category naturally also has this functionality

 

specific look screenshot:

 

 

call example:

 

 

 

 

 

open plug-in SubSonic.Schema folder StoredProcedure.cs file, find the Execute () function, in this function by adding the following code:

 
  
/// <summary> 
/// 执行存储过程,返回首行首列值
/// </summary>
public object ExecuteScalar() {
return Provider.ExecuteScalar(Command);
}

/// <summary>
/// 执行存储过程,返回指定的(泛)类型
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
public T ExecuteSingle<T>() where T : new()
{
return Provider.ExecuteSingle<T>(Command);
}
 
 

specific look screenshot:

 

 

 

call example:

 

 

 

After adding the above code, it will SubSonic3.0 plugin source to regenerate what you can normally use.

 

 

This article is original content, reproduced Please keep the following information.

 

contents of the publication of this series, as long as the main order and common learning and common progress, interested friends can jerk Q group: SubSonic3 .0 study group (327 360 708) or Email me (1654937 # qq.com), we explore, because my work is very busy, and if questions, please leave a message, reply is not timely please understand.

 

want to learn more SubSonic3.0 related issues, please view note blog: http://www.cnblogs.com/EmptyFS/ < / p>  

没有评论:

发表评论