Hello,
I'm using .NET 3.5 SP1.
I have a stored procedure returning a result of a transaction as shown below:
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 price=@price WHERE itemid=@itemId
UPDATE order_table SET price=@price WHERE itemid=@itemId
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
I’m trying to get @@ERROR status code returned. In EF v1, I created FunctionImport 'SetPrice' and called it by creating method in 'mycontext' class as shown below:
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;
}
This resulted in following error:
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()
Please tell how to resolve the issue.
Thank You.