0

I'm using EF 4.3 to execute a stored procedure which just deletes some records and returns 0 when successfull else 1. When i execute the sp (using this.DbContext.Database.ExecuteSqlCommand(sql, id)) i'm getting -1 which is not what i'm expecting.

Can someone tell me what's wrong?

Basically the stored procedure is very simple:

BEGIN TRY
    -- Delete records here
END TRY

BEGIN CATCH
    IF @@TRANCOUNT > @BeginTranCount
        ROLLBACK TRANSACTION
    RETURN 1
END CATCH

IF @@TRANCOUNT > @BeginTranCount
    COMMIT TRANSACTION
RETURN 0

Also the sp doesn't return value with out variable.

4

1 回答 1

0

我们确实需要查看您的代码,但总体思路如下:

SqlParameter parm = new SqlParameter() {  
    ParameterName = "@MyID",  
    SqlDbType = SqlDbType.Int,
    Direction = System.Data.ParameterDirection.Output  
}; 

Database.ExecuteSqlCommand("exec @MyId = dbo.MyProc", id);
int retyrnedId = (int)id.Value;
于 2013-01-25T10:48:26.880 回答