Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6015373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:49:37+00:00 2026-05-23T02:49:37+00:00

I have the following nested SQL Statement and i will to do the same

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:49:38+00:00Added an answer on May 23, 2026 at 2:49 am

    This will give you a new anonymous type which will have the board record and the count of discussion topics.

    var result = dataContext.Board.Select(x => new {x, Count = x.DiscussionTopics.Count()});
    

    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 correctly

    UPDATE

    If you have no foreign keys then this might do it

    var result = dataContext.Board.Select(x => new {x, Count = dataContext.DiscussionTopics.Count(d => d.TopicBoardId == x.BoardID)});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I have a question taken from pg 16 of IBM's Nested Relational Database White
Imagine the following sql query: UPDATE MYTABLE SET COL2 = (SELECT COL2 + 1
I have a procedure SelectProc which contains a SELECT statement. I want to add
Using Sax ActiveX Scripting (long story), I have 3 nested if statements which reuse
I have the following nested viewmodel class... public class CustomerModel { public string name;
I have been trying to optimize the two following nested loops: def startbars(query_name, commodity_name):
i have following code #include <iostream> #include <set> #include <string> using namespace std; template<class
I have the following Dto and entity with a nested sub entity. public class
I've been following RailsCast 197 to try this nested models/forms and have cracked my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.