Video Fetching Tables and Columns name in LINQ to SQL


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GetTableNameandColumnName
{
    class Program
    {
        static void Main(string[] args)
        {
            DataClasses1DataContext context = new DataClasses1DataContext();

            #region All Tables Name

            var dataModel = context.Mapping.GetTables();
            foreach (var r in dataModel)
            {
                Console.WriteLine(r.TableName);
            }

            Console.ReadKey(true);

            #endregion

            #region Columns Name of Person table
            foreach (var r in dataModel)
            {
                if (r.TableName.Equals("dbo.Person", StringComparison.InvariantCultureIgnoreCase))
                {
                    foreach (var r1 in r.RowType.DataMembers)
                    {
                        Console.WriteLine(r1.MappedName);
                    }
                }
            }

            #endregion

            Console.ReadKey(true);
        }
    }
}

*********************************

Add to FacebookAdd to DiggAdd to Del.icio.usAdd to StumbleuponAdd to RedditAdd to BlinklistAdd to TwitterAdd to TechnoratiAdd to Yahoo BuzzAdd to Newsvine


Discover more from Dhananjay Kumar

Subscribe to get the latest posts sent to your email.

Published by Dhananjay Kumar

Dhananjay Kumar is founder of NomadCoder and ng-India

One thought on “Video Fetching Tables and Columns name in LINQ to SQL

  1. How do you select multiple table names with — if (r.TableName.Equals(“dbo.Person”, StringComparison.InvariantCultureIgnoreCase))
    using checkedlistbox to populate multiple tablenames columns?

Leave a comment

Discover more from Dhananjay Kumar

Subscribe now to keep reading and get access to the full archive.

Continue reading