public List<Comment> GetComents(Guid postId)
{
string queryString =
"SELECT [dbo].comments.text, [dbo].comments.createdtime, comments.accountid, comments.name, comments.comid, comments.postid " +
"FROM [dbo].comments " +
"WHERE [dbo].comments.postid = @postid;";
using (SqlConnection connection = new SqlConnection(_connectionString))
{
var command = new SqlCommand(queryString, connection);
command.Parameters.AddWithValue("postid", postId);
connection.Open();
var reader = command.ExecuteReader();
var list = new List<Comment>();
if (reader == null)
return null;
while (reader.Read())
{
list.Add(new Comment()
{
Text = (string)reader[0],
CreatedTime = (DateTime)reader[1],
AccountId = (Guid)reader[2],
AuthorName = (string)reader[3],
ComId = (Guid)reader[4],
PostId = (Guid)reader[5]
});
}
return list;
}
}