DataAdapter を使用したクエリ
CData ADO.NET Provider for GraphQL では、次の2つのネイティブ.NET インターフェースを使用して、GraphQL からデータを取得できます。GraphQLDataAdapter オブジェクトおよびGraphQLDataReader オブジェクト。各オブジェクトは同じタスク(データの取得)を実行しますが、実行方法が異なります。GraphQLDataAdapter オブジェクトはクエリに一致するすべてのデータを取得しますが、GraphQLDataReader オブジェクトは必要に応じてインクリメントしながら一部のデータだけをフェッチします。
GraphQLDataAdapter の使用
アダプターのFill メソッドを使用して、データソースからデータを取得します。空のDataTable インスタンスがFill メソッドへの引数として渡されます。このメソッドが戻ってきたとき、DataTable インスタンスにはクエリされたデータが設定されています。Fill メソッドは、戻る前にデータソースからすべてのデータを取得する必要があるため、GraphQLDataAdapter はGraphQLDataReader よりも時間がかかります。
次の例は、Users テーブルのName カラムとEmail カラムを選択します。
C#
string connectionString = "AuthScheme=OAuth;OAuthVersion=2.0;CallbackURL=http://localhost:33333;OauthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;OAuthAccessTokenURL=https://mysite.com/login/oauth/access_token;"; using (GraphQLConnection connection = new GraphQLConnection(connectionString)) { GraphQLDataAdapter dataAdapter = new GraphQLDataAdapter( "SELECT Name, Email FROM Users", connection); DataTable table = new DataTable(); dataAdapter.Fill(table); Console.WriteLine("Contents of Users."); foreach (DataRow row in table.Rows) { Console.WriteLine("{0}: {1}", row["Name"], row["Email"]); } }
VB.NET
Dim connectionString As String = "AuthScheme=OAuth;OAuthVersion=2.0;CallbackURL=http://localhost:33333;OauthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;OAuthAccessTokenURL=https://mysite.com/login/oauth/access_token;" Using connection As New GraphQLConnection(connectionString) Dim dataAdapter As New GraphQLDataAdapter("SELECT Name, Email FROM Users", connection) Dim table As New DataTable() dataAdapter.Fill(table) Console.WriteLine("Contents of Users.") For Each row As DataRow In table.Rows Console.WriteLine("{0}: {1}", row("Name"), row("Email")) Next End Using