私は.NET 3.5 SP1を使用しています。エンティティフレームワークでストアドプロシージャ@@ ERROR値を取得するには?
私は、以下のようにトランザクションの結果を返すストアドプロシージャを持っている:
Create PROCEDURE SetPrice
@itemId int,
@price int
AS
DECLARE @myERROR int -- Local @@ERROR
, @myRowCount int -- Local @@ROWCOUNT
SET NOCOUNT ON
BEGIN TRAN1
UPDATE item_price_table SET [email protected] WHERE [email protected]
UPDATE order_table SET [email protected] WHERE [email protected]
SELECT @myERROR = @@ERROR, @myRowCount = @@ROWCOUNT
IF @myERROR != 0 GOTO HANDLE_ERROR
COMMIT TRAN1 -- No Errors, so go ahead
RETURN 0
HANDLE_ERROR:
ROLLBACK TRAN1
RETURN @myERROR
私は@@ ERRORステータスコードが返さ取得しようとしています。 EF v1ので、私はFunctionImport 'SetPrice' を作成し、以下のように 'あるMyContext' クラスのメソッドを作成することによって、それを呼び出した:
The data reader returned by the store data provider does not have enough columns for the query requested. at System.Data.EntityClient.EntityCommandDefinition.ConstantColumnMapGenerator.System.Data.EntityClient.EntityCommandDefinition.IColumnMapGenerator.CreateColumnMap(DbDataReader reader) at System.Data.EntityClient.EntityCommandDefinition.Execute(EntityCommand entityCommand, CommandBehavior behavior) at System.Data.EntityClient.EntityCommand.ExecuteReader(CommandBehavior behavior) at System.Data.EntityClient.EntityCommand.ExecuteScalar[T_Result](Func`2 resultSelector) at System.Data.EntityClient.EntityCommand.ExecuteScalar()
:
public int SetPrice(int itemId, int price) {
Int32 result = -1;
EntityCommand cmd = ((EntityConnection)this.Connection).CreateCommand();
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "myContext.SetPrice";
cmd.Parameters.AddWithValue("itemId", itemId);
cmd.Parameters.AddWithValue("price", price);
EntityParameter retParameter = new EntityParameter();
retParameter.Direction = System.Data.ParameterDirection.ReturnValue;
cmd.Parameters.Add(retParameter);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
result = Convert.ToInt32(retParameter.Value);
cmd.Connection.Close();
return result;
}
これは、次のエラーが発生しました
問題の解決方法を教えてください。
ありがとうございました。
+1確かに@@ ERRORは信じられないほど多くの点で欠陥があります。 –
ありがとうございます。 EF v1でSPサポートを探るサンプルストアドプロシージャを作成しました。 – dev