我试过了,但是我在这一次失败了。所以我试着帮助你。
我有一个没有输入参数的存储过程,但我喜欢返回一些结果值(3个值为int)。
我创建了存储过程并将其添加到EF但我得到一个整数,而不是3个值。
我的存储过程代码:
IF NOT EXISTS (SELECT Name FROM sys.objects
WHERE OBJECT_ID = OBJECT_ID(N'dbo.ExtendUncanceldContracts'))
EXECUTE sp_executesql N'CREATE PROCEDURE dbo.ExtendUncanceldContracts AS BEGIN SELECT 1 AS ID END';
GO
ALTER PROCEDURE dbo.ExtendUncanceldContracts
AS
BEGIN
BEGIN TRY
/* Do a lot of stuff */
EXEC AnotherStoredProcedure @AnId
DECLARE @tt INT;
DECLARE @ur INT;
DECLARE @ufr INT;
SET @tt = (SELECT COUNT(*) FROM #UpdateTableTemp)
SET @ur = (SELECT COUNT(*) FROM #UpdateTable1Temp)
SET @ufr = (SELECT COUNT(*) FROM #UpdateTable2Temp)
DECLARE @tablevar AS TABLE (tt INT, ur INT, ufr INT)
INSERT INTO @tablevar (tt, ur, ufr)
VALUES (@tt, @ur, @ufr)
SELECT * FROM @tablevar
END TRY
BEGIN CATCH
DECLARE @ErrorState INT = ERROR_STATE(),
@ErrorSeverity INT = ERROR_SEVERITY(),
@ErrorMessage NVARCHAR(4000) = ISNULL(ERROR_PROCEDURE(),'<noProcName>');
RAISERROR (@ErrorMessage,@ErrorSeverity,@ErrorState);
END CATCH
END
我的C#代码
public bool ExtendUncanceldContracts()
{
try
{
var res = (from o in ctx.ExtendUncanceldContracts()
select o).ToList();
ctx.SaveChanges();
return true;
}
catch (Exception ex)
{
throw new Exception("Some error Text");
}
}