DataConnector
接続の作成
ADO.NET provider for OData > 接続の作成

To create a connection to an OData data source, the ADO.NET Provider can be used through the C1ODataConnection class. This class requires a connection string to be provided as an argument, which can be created in either of the following ways:

Connection string generation

The code example below shows how a connection string can be configured by the C1OdataConnectionStringBuilder class and consumed by the C1ODataConnection class to create a connection to the OData server. Through that connection, the data source can be queried, updated etc.

C#
コードのコピー
// odata.org のサービスの URL。
const string NorthwindSampleUrl = "https://services.odata.org/V4/Northwind/Northwind.svc";

// 接続文字列を設定します。

var builder = new C1ODataConnectionStringBuilder();
builder.Url = NorthwindSampleUrl;
builder.UsePool = true;

// 接続を設定します。
var con = new C1ODataConnection(builder.ConnectionString);

Connection string literal

Alternatively, the connection string can be written directly as a string literal, like in the code example below (a similar approach can be implemented in other DataConnectors for ADO.NET provider).

C#
コードのコピー
// 接続文字列全体。
var connectionString = "Url=https://services.odata.org/V4/Northwind/Northwind.svc; Use Pool=true";

// 接続を設定します。
var con = new C1ODataConnection(connectionString);

Note: Connection strings can be formed by using as connection keys the names of the corresponding properties of C1OdataConnectionStringBuilder, but with an added space character. For example, to set the property UseCache, the connection key should be written as Use Cache.

OData versions

By default, the provider assumes that the latest version of OData (version 4) is being used. If a different version of OData is used, the "odata version" property needs to be set to the specific OData version in the connection string. For example, if OData version 2 is being used, "odata version=2" needs to be specified in the connection string.

Example Title
コードのコピー
var connectionString = "https://services.odata.org/V2/(S(f5su0fte55y534onqz3zvfgf))/OData/OData.svc/; odata version = 2";