Tuesday 3 September 2013

Querying database schema with Linq to SQL

Querying database schema with Linq to SQL

I'm trying to write an application which I can point at different
databases and look at the database's schema, i.e. tables and their
column's properties, relationships, constraints etc. I've been looking
into the Linq to SQL method GetTable(), but this appears to return
nothing;
public static IEnumerable<MetaTable> GetMetaTables() { using (var
connection = new SqlConnection(ConnectionString)) using (var context = new
SchemaDataContext(connection)) return
context.Mapping.GetTables().ToList(); }
What am I doing wrong!?

No comments:

Post a Comment