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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:01:29+00:00 2026-05-11T15:01:29+00:00

I am trying to get into LINQ to objects as I can see the

  • 0

I am trying to get into LINQ to objects as I can see the power of it. Lucky enough I have a question that I think LINQ should be able to solve.

Here is the question (the details are an example);

public class SchoolClass {     public int ID;     public string Name;     public string Teacher;     public string RoomName;      public string Student_Name;     public int Student_Age; } 

As you can see by the example, there is a one to many relationship between the ClassName, Teacher and Room and the Students, i.e. there are potentially many students in the one class.

If we have a List is it possible using LINQ to create a List but have only one instance ID, Name, Teacher, RoomName and an ArrayList of Student_Name and Age?

Producing this:

public class Students {     public string Student_Name;     public int Student_Age; }  public class SchoolClass {     public int ID;     public string Name;     public string Teacher;     public string RoomName;      public ArrayList Students; } 

Essentially, using LINQ to clean the List to a more logical structure?

To give some background to this example. The second structure is used by a DataGrid to produce a Master-Child relationship. We store SchoolClass and StudentInformation in classes as shown above. It would be good use of LINQ to be able to convert our initial List into a structure which can be used by the DataGrid.

  • 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. 2026-05-11T15:01:30+00:00Added an answer on May 11, 2026 at 3:01 pm

    I changed the ArrayList to List<Students>, and:

        List<SourceData> source = new List<SourceData>();     //...your data here ;-p     var classes = (from row in source                   group row by new {                           row.ID, row.Name,                           row.Teacher, row.RoomName }                       into grp                       select new SchoolClass                       {                           ID = grp.Key.ID,                           Name = grp.Key.Name,                           Teacher = grp.Key.Teacher,                           RoomName = grp.Key.RoomName,                           Students = new List<Students>(                               from row in grp                               select new Students                               {                                   Student_Age = row.Student_Age,                                   Student_Name = row.Student_Name                               })                       }).ToList(); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get some XML data with LINQ, but running into a
I ran into an error when trying to serialize a linq entitySet. To get
I am trying to insert a record into a table using Linq but get
I am trying to get into android development, after some reading i have settled
I have this code, but can't get it all working. I am trying to
I'm trying to use LINQ To Objects to create a query that will give
I have been playing about with LINQ-SQL, trying to get re-usable chunks of expressions
I have a set of subclassed domain objects that I fetch with Linq and
Today I have been trying to get an image to save into a database,
Im trying to get into some basic JavaFX game development and I'm getting confused

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.