【发布时间】:2010-12-15 02:41:38
【问题描述】:
我正在尝试将两个数组与其关系相结合,但无法做到。 我的数据库上有一个 Posts 表,在 Posts 表中有问题和答案记录。答案与“relatedPostId”列上的问题有关。 例如:
Posts (Table)
-------------
int Id (Field)
string Text (Field)
int RelatedPostId (Field)
question(record) : relatedPostId column is null
answer(record) : relatedPostId column is the value of question id
我的代码如下所示
var posts = DBConnection.GetComments(_post.TopicId).ToArray().OrderByDescending(p => p.CreateDate);
var questions = posts.Where(p => p.RelatedPostId == null);
var answers = posts.Where(p => p.RelatedPostId != null);
var result = from q in questions
join a in answers
on q.Id equals a.RelatedPostId
select new { q = q, a = a };
我想在 ListBox 上列出帖子 (lstCurrentTopic.Items.AddRange(...)) 我还想在每个问题的末尾显示答案,例如
Question1
-> Answer1 (relatedPostId is Qustion1.Id)
-> Answer2 (relatedPostId is Qustion1.Id)
Qestion2
->Answer3 (relatedPostId is Qustion2.Id)
->Anser4 (relatedPostId is Qustion2.Id)
如何将此订单添加到列表框
【问题讨论】: