-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSchema.cs
55 lines (44 loc) · 1.42 KB
/
Schema.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System.Collections.Generic;
using System.Data.SqlClient;
namespace SatelliteDataScripter
{
public class Schema
{
private IEnumerable<Table> tables;
public Connection Connection { get; private set; }
public string Name { get; set; }
public IEnumerable<Table> Tables
{
get
{
if (tables == null)
{
tables = LoadTables();
}
return tables;
}
}
public Schema(Connection connection, TablesDataSet.SchemaRow row)
{
Connection = connection;
Name = row.Table_Schema;
}
public override string ToString()
{
return Name;
}
private IEnumerable<Table> LoadTables()
{
using (var adapter = new SqlDataAdapter("select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_TYPE = 'BASE TABLE' and TABLE_SCHEMA like @schema order by 1", Connection.ConnectionString))
{
adapter.SelectCommand.Parameters.AddWithValue("@schema", Name);
var dataTable = new TablesDataSet.TableDataTable();
adapter.Fill(dataTable);
foreach (TablesDataSet.TableRow row in dataTable.Rows)
{
yield return new Table(this, row);
}
}
}
}
}