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

One response to “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

Create a website or blog at WordPress.com