The ADO.NET provider for OData supports schema discovery using ADO.NET classes or SQL statements to the system tables. This is done through the GetSchema method of the C1ODataConnection class, optionally specifying schema name and restriction values.
In the code example below, GetSchema method is called firstly to return the Tables of the database, then called again to return the Columns of a specific datatable.
C# |
コードのコピー
|
---|---|
using (var connection = new C1ODataConnection(connstr)) { connection.Open(); // テーブルのリストを取得します。 DataTable databaseTables = connection.GetSchema("Tables"); Console.WriteLine("List of Tables in database:\n"); foreach (DataRow row in databaseTables.Rows) { // テーブル名を出力します。 Console.WriteLine(row["TableName"]); } // テーブル内の列名を取得します。 DataTable datatableColumns = connection.GetSchema("Columns", new string[] { "Products" }); Console.WriteLine("\n Products table columns:"); foreach (DataRow column in datatableColumns.Rows) { // 列のプロパティを出力します。 Console.Write(column["ColumnName"]); Console.Write("\t" + column["DataType"]); Console.Write("\t" + column["AllowDbNULL"] + "\n"); } } |
Alternatively to the GetSchema method, the GetSchemaTable method of the C1DataReader class can be used, which returns a DataTable with the definitions of the column metadata.