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

  • SEARCH
  • Home
  • 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 5966441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:48:03+00:00 2026-05-22T19:48:03+00:00

[Firstid foreignId field] [1 1 textFirst1] [2 1 textFirst2] [3 1 textFirst3] [4 2

  • 0
[Firstid foreignId field]
[1       1         textFirst1]
[2       1         textFirst2]
[3       1         textFirst3]
[4       2         textFirst4]
[5       2         textFirst5]

and

[Secondid foreignId field]
[1        1         textSec1]
[2        1         textSec2]
[3        2         textSec3]

foreignId reffer to the same table
MY question is how to write linq2Sql query to retrive following result:

[foreignId countFromSecond fieldFromFirst]
[1         2               textFirst1]
[1         2               textFirst2]
[1         2               textFirst3]
[2         1               textFirst4]
[2         1               textFirst5]

other words, i want to retrive almost first table without id but gruoped with count from second table

  • 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-22T19:48:03+00:00Added an answer on May 22, 2026 at 7:48 pm

    Something like this:

    var query =
        from first in db.FirstTable
        select
            new
            {
                first.foreignId,
                countFromSecond = db.SecondTable
                    .Where(arg => arg.foreignId == first.foreignId)
                    .Count(),
                first.fieldFromFirst
            };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an insert statement: insert into parentTbl select firstId, secondId, thirdId, dateTm from
This is my JavaScript function: function switch_div(firstID,secondID) { if((document.getElementById(firstID).style.display == 'inline') && (document.getElementById(secondID).style.display ==
class first { private int? firstID; } class second { private int secondID; private
public ClassA { private String firstId; private String secondId; public void setFirstId(String firstId) {
How to update (change from first select table value second) second_table.first_table_id if first_table.email match
I have got the following table where if more than 1 row contain the
I've got a painfully simple table that is giving me a Specified cast is
@TableGenerator(name = trial, table = third, pkColumnName = a , valueColumnName = b, pkColumnValue
Good afternoon in my timezone. I have a table with four tr and each
I have a database scheme with versioning data rows, e.g. Table Person has the

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.