
GetPosts
public override PostSet GetPosts(BlogPostQuery query)


{
using( SqlConnection connection = GetSqlConnection() )

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

{
command.CommandType = CommandType.StoredProcedure;

command.Parameters.Add("@SectionID", SqlDbType.Int).Value = query.BlogID;
//14
//SectionID,个人Blog的记录的ID

command.Parameters.Add("@PostID", SqlDbType.Int).Value = query.PostID;
//12
//Blog记录的ID

command.Parameters.Add("@PostName", SqlDbType.NVarChar).Value = query.Name;
//null
//不知道

command.Parameters.Add("@PageIndex", SqlDbType.Int, 4).Value = query.PageIndex;
//0
//不知道

command.Parameters.Add("@PageSize", SqlDbType.Int, 4).Value = query.PageSize;
//20
//不知道

command.Parameters.Add("@ReturnFullThread", SqlDbType.Bit, 1).Value = query.ReturnFullThread;
//true
//不知道

command.Parameters.Add("@UserID", SqlDbType.Int).Value = query.UserID;
//0
//因为未登录,所以为0,如果登录则为登录者的ID,不是数据库中记录那个GUID

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

command.Parameters.Add("@TotalRecords", SqlDbType.Int).Direction = ParameterDirection.Output;
//
//准备返回的参数

PostSet ps = new PostSet();

connection.Open();

//NOTE TO SELF: We return the results as seperate sets so that we can avoid some of the more
//expensive lookups done ont the main posts!
using(SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection))

{
//this will return just one post, forget the rest if nothing found here
if(reader.Read())

{
WeblogPost entry = PopulateWeblogEntryFromIDataReader(reader);
//PopulateWeblogEntryFromIDataReader(reader,entry);
if(query.IncludeCategories)

{
reader.NextResult();
ArrayList categories = new ArrayList();
while(reader.Read())

{
categories.Add(reader["Name"] as string);
}
entry.Categories = (string[])categories.ToArray(typeof(string));
}
//we could be setting the thread starter right here?
ps.Posts.Add(entry);

//comment list
reader.NextResult();

while(reader.Read())

{
entry = PopulateWeblogEntryFromIDataReader(reader);
//PopulateWeblogEntryFromIDataReader(reader,entry);

ps.Posts.Add(entry);
}

reader.NextResult();
ps.TotalRecords = (int) command.Parameters["@TotalRecords"].Value;

reader.Close();
}
else

{
reader.Close();
}
}

connection.Close();

return ps;

}
}
}

posted on
2005-10-17 17:59 Konimeter 阅读(92) 评论()
编辑 收藏