函数参数为BlogThreadQuery类型的自定义对象变量
函数返回为ThreadSet类型的自定义对象变量
GetBlogThreads
public override ThreadSet GetBlogThreads(BlogThreadQuery query)

{
using( SqlConnection connection = GetSqlConnection() )

{
using(SqlCommand command = new SqlCommand(databaseOwner + ".cs_weblog_Posts_GetPostSet", connection))

{
command.CommandType = CommandType.StoredProcedure;

//以下各行代码下面的注释:第一行为例子时的值,第二行开始为个人注释
command.Parameters.Add("@SectionID", SqlDbType.Int).Value = query.BlogID;
// 14
//实际意义为:氯胺酮的Blog(自己建立的)
//如果是论坛,则为版块的ID
//ps:GroupID为版块集合区的ID,就是说,一个Group下面有多个Section
command.Parameters.Add("@PageIndex", SqlDbType.Int, 4).Value = query.PageIndex;
//0

command.Parameters.Add("@PageSize", SqlDbType.Int, 4).Value = query.PageSize;
//15

command.Parameters.Add("@sqlPopulate", SqlDbType.NText).Value = SqlGenerator.BuildBlogThreadQuery(query,databaseOwner);
//SET Transaction Isolation Level Read UNCOMMITTED Select top 15 P.PostID From dbo.cs_Posts P, dbo.cs_weblog_Posts B where P.SectionID = 14 and B.PostID = P.PostID and P.PostLevel = 1 and B.BlogPostType & 1 <> 0 and P.SettingsID = 1000 and B.SettingsID = 1000 and B.PostConfig & 1 = 1 and P.IsApproved = 1 and P.PostDate <= getdate() Order by P.PostDate desc

command.Parameters.Add("@UserID", SqlDbType.Int).Value = query.UserID;
// 2105
//怎样从GUID换算成这么一个int?
//是否每次不一样?经过第二次跟踪每次一样
//好像不是经过换算,跟踪其他用户的ID,发现在我公司起的这个CS里,每个userid都是从21开头,4位整数
//2101,2102,2105。。。

command.Parameters.Add("@IncludeCategories", SqlDbType.Bit).Value = query.IncludeCategories;
//false

command.Parameters.Add("@TotalRecords", SqlDbType.Int).Direction = ParameterDirection.Output;
command.Parameters.Add(SettingsIDParameter());

ThreadSet ts = new ThreadSet();

// Execute the command
//If we want to display the list of categories for the post, we will need to
//use a dataset so we can join the child records
if(query.IncludeCategories)

{
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(command);

//wait as long as possible to open the conn
connection.Open();
da.Fill(ds);
connection.Close();

//keep a referece to the relation since it is used in the GetChildRows look up anyway
DataRelation relation = new DataRelation("Categories",ds.Tables[0].Columns["PostID"],ds.Tables[1].Columns["PostID"],false);
ds.Relations.Add(relation);
DataRowCollection posts = ds.Tables[0].Rows;
foreach(DataRow dr in posts)

{
ts.Threads.Add(PopulateWeblogPostContentFromDataRow(dr,relation));
}
ds.Clear();
ds.Dispose();

ts.TotalRecords = (int) command.Parameters["@TotalRecords"].Value;

}
else

{
//No categories needed, so we can use a datareader.

connection.Open();
using(SqlDataReader dr = command.ExecuteReader(CommandBehavior.CloseConnection))

{
while(dr.Read())

{
ts.Threads.Add(PopulateWeblogPostContentFromIDataReader(dr));
}

// if(query.IncludeCategories)
// dr.NextResult();

dr.NextResult();
ts.TotalRecords = (int) command.Parameters["@TotalRecords"].Value;
}
}

return ts;

}
}
}