I have the following nested SQL Statement and i will to do the same using Lambda statement in C# How do i do it?
SQL:
SELECT board.*, (SELECT COUNT(*) from discussion_topic
WHERE TopicBoardID=board.BoardID) as TopicCount
FROM `discussion_board` as board
This is the structure of my 2 tables
Table Name: discussion_board
Fields:
BoardID
BoardName
BoardCreatedBy
BoardCreatedDate
Table Name: discussion_topic
Fields:
TopicID
TopicName
TopicCreatedBy
TopicCreatedDate
TopicBoardID
just 2 simple tables with no Forign Keys,
Thank you!
This will give you a new anonymous type which will have the board record and the count of discussion topics.
You could simply use
board.DiscussionTopics.Count();on each record to get the count. No need to do the above really, if i understand your question correctlyUPDATE
If you have no foreign keys then this might do it