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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:40:24+00:00 2026-05-25T11:40:24+00:00

How do you get the column names from a db? Currently, I’m interacting with

  • 0

How do you get the column names from a db?

Currently, I’m interacting with the db through linq-sql using an ado.net entity model. I’ve searched through StackOverflow and I got a few helpful posts but nothing I’ve tried has worked.

Like take this post:

How do I return the column names of a LINQ entity

I tried the responses from Conrad Frix but they didn’t work. I’m not exactly sure what he means by a ‘Datacontext’ anyway. Is that Entity?

    AttributeMappingSource mappping = new System.Data.Linq.Mapping.AttributeMappingSource();
    var model = mappping.GetModel(typeof (AdoModelEntities));
    var table = model.GetTable(typeof (TableName));

    var qFields= from fields in table.RowType.DataMembers
            where fields.IsPersistent == true
            select fields;

    foreach (var field in qFields)
        Console.WriteLine(field.Name);

This doesn’t work because table is null

  • 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-25T11:40:24+00:00Added an answer on May 25, 2026 at 11:40 am

    You can do something like this…

    Object LinqObject = Activator.CreateInstance(tableName, null);
    
    //For each field in the database (or property in Linq object)
    foreach (PropertyInfo pi in LinqObject.GetType().GetProperties())
    {     
         String name = pi.Name;
    }
    

    LinqObject would be the table object you are trying to get names on. It doesn’t matter how you create it. That’s a way to create it if you just have the string name.

    Assuming your .dbml had a table named “Order” it would work just as well to do:

    Object LinqObject = new Order();
    

    You don’t have to declare the reference to the table object as an Object either obviously.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking to get a list of the column names returned from a
I have a few windwos services. They get xml column from Sql server manipulate
I need to query the database to get the column names , not to
I am after a code to get the available column names of a table
Given a columns' index, how can you get an Excel column name? The problem
How can i get a column in an SSRS 2005 report to render control
In a bash script, I want to get the cursor column in a variable.
How to get average of a column in terms of another column and put
How do I get the current line and column numbers in a RichTextBox in
I have a (rather complicated) SQL statement where I select data from lots of

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.