2015-10-19 46 views
0

我的問題相同this。但我不明白solution.in我的SP參數「@OperationType」確定什麼是操作類型(如果1然後插入,如果2然後更新,如果3然後刪除) 我的存儲程序是這樣的:如何在Entity Framework中使用相同的存儲過程插入,更新和刪除?

ALTER PROCEDURE [dbo].[JobOperation] (
@ID      INT = NULL OUTPUT, 
@JobTitle     NVARCHAR(50) = NULL, 
@JobLevel     NVARCHAR(50) = NULL, 
@Des      NVARCHAR(MAX) = NULL, 
@IsDbCommandCommitted  BIT = 0 OUTPUT, 
@DbCommitError   VARCHAR(200) = NULL OUTPUT, 
@OperationType   INT = NULL, 
@LanguageID    INT = NULL 
) 
AS 
IF @operationType = 1 
BEGIN 
    BEGIN TRY 
     BEGIN TRANSACTION 
     INSERT INTO .... 

     SELECT @ID = MAX(ID) 
     FROM JOB 

     SET @IsDbCommandCommitted = 1 
     COMMIT TRANSACTION 
    END TRY 
    BEGIN CATCH 
     SET @DbCommitError = ERROR_MESSAGE() 
     ROLLBACK TRANSACTION 
    END CATCH 
END 
ELSE 
IF @OperationType = 2 
BEGIN 
    BEGIN TRY 
     BEGIN TRANSACTION 
     UPDATE JOB 
     ...... 

     SET @IsDbCommandCommitted = 1 
     COMMIT TRANSACTION 
    END TRY 
    BEGIN CATCH 
     SET @DbCommitError = ERROR_MESSAGE() 
     ROLLBACK TRANSACTION 
    END CATCH 
END 
ELSE 
IF @OperationType = 3 
BEGIN 
    BEGIN TRY 
     BEGIN TRANSACTION 
     DELETE 
     FROM JOB 
     WHERE ID = @ID 

     SET @IsDbCommandCommitted = 1 
     COMMIT TRANSACTION 
    END TRY 
    BEGIN CATCH 
     SET @DbCommitError = ERROR_MESSAGE() 
     ROLLBACK TRANSACTION 
    END CATCH 
END 

有什麼想法嗎?

+0

您在使用我的Windows應用程序不asp.net嘗試新鮮事物 –

回答

1

Pass parameter Using EF

按照本教程通過使用EF的參數,以此來SP,這應該解決您的查詢

+0

。 –

+0

c#和EF進程不會改變,因爲我知道關閉 –

+0

單擊「獲取列信息」參數時不顯示並顯示此消息:「選定的存儲過程或函數不返回列」 –

相關問題