SELECT
[Project1].[TopicId] AS [TopicId],
[Project1].[TopicTitle] AS [TopicTitle],
[Project1].[C1] AS [C1],
[Project1].[ReplyId] AS [ReplyId],
[Project1].[TopicId1] AS [TopicId1],
[Project1].[ReplyMessage] AS [ReplyMessage]
FROM ( SELECT
[Extent1].[TopicId] AS [TopicId],
[Extent1].[TopicTitle] AS [TopicTitle],
[Extent2].[ReplyId] AS [ReplyId],
[Extent2].[TopicId] AS [TopicId1],
[Extent2].[ReplyMessage] AS [ReplyMessage],
CASE WHEN ([Extent2].[ReplyId] IS NULL) THEN CAST(NULL AS int) ELSE 1 END AS [C1]
FROM [dbo].[Topic] AS [Extent1]
LEFT OUTER JOIN [dbo].[Reply] AS [Extent2] ON [Extent1].[TopicId] = [Extent2].[TopicId]
) AS [Project1]
ORDER BY [Project1].[TopicId] ASC, [Project1].[C1] ASC