Search code examples
.netlinqasp.net-3.5datacontext

Linq: Get a list of all tables within DataContext


I have a DataContext (Linq to Sql) with over 100 tables, is it possible to get a list of all those tables and lets say print them to the console? This might be a silly question.

Thanks.


Solution

  • It's much easier than above and no reflection required. Linq to SQL has a Mapping property that you can use to get an enumeration of all the tables.

    context.Mapping.GetTables();