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

Advertisements

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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s