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 6872619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:57:08+00:00 2026-05-27T03:57:08+00:00

If I had a SQL Server table that looks something like this with some

  • 0

If I had a SQL Server table that looks something like this with some authors appearing in multiple rows (meaning they authored multiple books).

BookID INT;
BookTitle NVARCHAR(100);
AuthorID INT;
AuthorName NVARCHAR(100);

Is there any way to write an Entity Framework expression that would populate a memory layout similar to the following?

class AuthorInfo
{
    int ID;
    string Name;
    IEnumerable<int> BookIDs;
}

In other words, I would to have one object for each author, but then have the BooksIDs collection contain all the books for that author.

I know I could first load the unique authors, and then iterate the resulting collection to add all matching books for each author. But is there any way to do something like this with a single linq statement?

  • 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-27T03:57:09+00:00Added an answer on May 27, 2026 at 3:57 am

    Does this work? (I haven’t tried it.)

    var authorInfos = DbContext.BooksAuthors
    .GroupBy (ba => new { AuthorId = ba.AuthorId, AuthorName = ba.AuthorName })
    .Select (g => new AuthorInfo { 
        ID = g.Key.AuthorId, 
        Name = g.Key.AuthorName,
        BookIDs = g.Select (ba => ba.BookId)
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My table structure (in SQL Server) looks something like this: (D1 is more recent
I have a table that looks like this: Month Site Val 2009-12 Microsoft 10
With SQL Server 2008 SP1, I've removed the only table that had a Filestream
I've got a table that looks like this (I wasn't sure what all might
I am using Microsoft SQL Server. I have a Table which had been updated
i already had 2008 express sql server but for some reason it came without
I had someting like this in my code (.Net 2.0, MS SQL) SqlConnection connection
I have a SQL Server 2008 database table that uses uniqueidentifier as a primary
I have a single row of data in a SQL Server table that I'm
I have a SQL Server 2005 database that stores data for multiple users. Each

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.