|
ADO.NET Entity Framework でストアド プロシージャを使用するには、関数のマッピングが必要です。このようなストアド プロシージャの呼び出しは複雑で、いくらかのコーディングを必要とします。
Connection オブジェクトには、拡張された統計情報機能を提供するためのプロパティおよびメソッドが含まれています。これらは、ADO.NET データ プロバイダーでは標準ですが、ADO.NET Entity Framework レイヤーでは利用できません。代わりに、「疑似」ストアド プロシージャを介して同様の機能を公開します。
この方法では、エンティティ データ モデル(EDM)を使用して、ADO.NET の結果に対応する結果を得ます。これは実質的に、疑似ストアド プロシージャから戻されるエンティティおよび関数を提供します。
表 23 は、データ プロバイダーの Connection プロパティから対応する疑似ストアド プロシージャへのマッピングを示します。
次の C# コードで示されているように、アプリケーションは ObjectContext を使用してストアド プロシージャ コマンドを作成する必要があります。
using (MyContext context = new MyContext()) { EntityConnection entityConnection = (EntityConnection)context.Connection; // EntityConnection は基となるストア接続を公開します DbConnection storeConnection = entityConnection.StoreConnection; DbCommand command = storeConnection.CreateCommand(); command.CommandText = "Psql_Connection_EnableStatistics"; command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new PsqlParameter("cid", 1)); } // bool openingConnection = command.Connection.State == ConnectionState.Closed; if (openingConnection) { command.Connection.Open(); } int result; try { result = command.ExecuteNonQuery(); } finally { if (openingConnection && command.Connection.State == ConnectionState.Open) { command.Connection.Close(); } }
オーバーロードされたストアド プロシージャが複数ある場合、Pervasive PSQL Entity Framework データ プロバイダーは各ストアド プロシージャに識別子を追加して、SSDL でそれらを識別できるようにします。データ プロバイダーは、アプリケーションでストアド プロシージャを呼び出す前に、追加した識別子を削除します。
|