我有一个SQL表:
ID | 发件人 | USERD_ID | 正文 | 标题 | THREAD_ID | 回复 |
---|---|---|---|---|---|---|
1 | 2 | 15 | 某物 | 一些标题 | 空 | 空 |
2 | 2 | 16 | 空 | 空 | 空 | 空 |
3 | 2 | 17 | 空 | 一些标题 | 空 | 空 |
4 | 1 | 15 | sth1 | 问题 | 501 | 1 |
5 | 3 | 15 | sth2 | 回答:问题 | 501 | 空 |
6 | 2 | 15 | 空 | 空 | 空 | 空 |
我想返回一个数据如下的列表:
[{id: 1, user_id: 15, body: "sth", title: "some title", threadMessage: null},
{id: 4, user_id: 15, body: "sth1", title: "question",
threadMessage: {messageId: 5,threadId: 501, body: "sth2", title: "answer: question"}},
{id: 6, user_id: 15, body: null, title: "null", threadMessage: null}]
我有一个这样的Quey:
var query = (from m in db.Message
where m.USERD_ID = 15
select new MessageTemp
{
Id = m.Id,
Body = m.Body,
Title = m.Title
})AsQueryable();
我不知道如何重写这个查询中的条件,如何才能为相同的Thread_ID获取有关MessageThread的信息.当然,我需要3项,而不是4项.