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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:56:53+00:00 2026-06-06T04:56:53+00:00

My app in ASP.NET C#. I use Linq to Sql, look the picuture //

  • 0

My app in ASP.NET C#. I use Linq to Sql, look the picuture

enter image description here

// 5 data talbe :

// Unit table

     id |   name    | unit_type_id          Unit_type   
       -------------------------                    
        1 | Unit 1  |     1                     id   |  name
        2 | Unit 2  |     1                     -------------   
        3 | Unit 3  |     1                     1    |  Type 1
        4 | Unit 4  |     2                     2    |  Type 2
        5 | Unit 5  |     1                     3    |  Type 3
        6 | Unit 6  |     3     




 //Tool table                                // tool_type   table

    id  |   name    | tool_type_id              id   |  name
    ----------------------------            ------------------- 
    1   |   Tool 1  |     1                     1    |  Tool_type 1
    2   |   Tool 2  |     2                     2    |  Tool_type 2
    3   |   Tool 3  |     1                     3    |  Tool_type 3
    4   |   Tool 4  |     2         
    5   |   Tool 5  |     3 

//unit_tool table

unit_id | tool_id
    ---------------
    1   |    1
    2   |    1
    1   |    2
    1   |    3
    2   |    2
    2   |    3
    3   |    3
    3   |    2

I want to use linq to sql in C# to get data like

// Table data i want to get

Unit name  |  Unit type name  | Tool name
-------------------------------------------------
Unit 1     | Type 1           | tool 1, tool 2, tool 3
Unit 2     | Type 1           | tool 1, tool 2, tool 3
Unit 3     | Type 1           | tool 2, tool 3
Unit 4     | Type 2           | 
Unit 5     | Type 1           | 
Unit 6     | Type 3           | 

My code be low

// Create new class

public class unit_list
    {
        //Unit name
        public string unit_name { get; set; }
        // Unit type name
        public string unit_type_name { get; set; }
        // Tool name
        public string tool_name { get; set; }
    }

// Function get data

protected void show_unit()
{
    // Create datacontext
    for_testDataContext db = new for_testDataContext();
    //Query data
    IQueryable<unit_list> CourseList = from cl in db.units
                                        select new unit_list()
                                        {
                                            unit_name = cl.name,
                                            unit_type_name = cl.unit_type.name,
                                            tool_name = // how to get data like "tool1, tool 2, tool 3"
                                        };

}
  • 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-06-06T04:56:55+00:00Added an answer on June 6, 2026 at 4:56 am

    You should be able to write something like this (assuming all the relationships are set up correctly in Linq):

    select new unit_list()
    {
        unit_name = cl.name,
        unit_type_name = cl.unit_type.name,
        tool_name = string.Join(", ", 
            cl.unit_tools.Select(ut => ut.tool.name).ToArray()
        )
    };
    

    In other words..

    1. Get the one-to-many relationship to unit_tools
    2. Select the corresponding row in tool and select the name column
    3. Join to get a single comma-separated string
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My app in ASP.NET C#, i use linq to sql to pass data from
I have an ASP.NET web app where I use an ado sql connection to
I have an asp.net web app which holds its data in an sql server
Trying to use use SharpSVN in an ASP.NET app. So far, it's been nothing
I´m building an asp.net app, which technology I should use to get AJAX capabilities?
We use ELMAH for our ASP.NET web app and I am stumped as to
In my Controller in a Asp.net MVC 1 app I want to use UpdateModel
I currently use the repository pattern in my ASP.NET MVC 3 app. I use
We're creating a new consumer/public-facing ASP.Net web app. There are two concerns: --Use cookie
I'm starting the development of a C#/ASP.net web app, within which I use 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.