以下存儲過程顯示三個字符串和一個表格行結果作爲輸出。 有什麼辦法可以使用實體框架在mvc視圖輸出面板上顯示所有結果?使用實體框架從存儲過程獲取多個字符串輸出
我可以在下面的代碼中看到第一個字符串結果。但是無論如何要得到另外兩個選擇字符串輸出和 表格結果。
private CustomerEntities db = new CustomerEntities();
public ActionResult Index()
{
var results = db.usp_CustomerData("124544", 1500);
var abc = results.ToList();
return View();
}
ALTER PROCEDURE [dbo].[usp_CustomerData]
@CustomerID varchar(6),
@MinsBack int
AS
BEGIN
DECLARE @Count int
SET @Count = (SELECT Count(*)
FROM Customer WITH (NOLOCK)
WHERE CustomerID = @CustomerID AND
DATEDIFF(mi, ReceivedAt, GETUTCDATE()) < @MinsBack)
IF (@Count = 1)
SELECT 'Ok: 1 message in Customer table'
ELSE
SELECT 'ERROR: Expected 1 message in Customer table, but found ' + CONVERT(varchar(3), @Count) + ' messages.'
SET @Count = (SELECT Count(*)
FROM CustomerDetails WITH (NOLOCK)
WHERE CustomerID = @CustomerID AND
DATEDIFF(mi, LastUpdatedAt, GETDATE()) < @MinsBack)
IF (@Count = 1)
SELECT 'Ok: 1 record in CustomerDetails table'
ELSE
SELECT 'ERROR: Expected 1 record in CustomerDetails table, but found ' + CONVERT(varchar(3), @Count) + ' records.'
SET @Count = (SELECT Count(*)
FROM CustomerProduct WITH (NOLOCK)
WHERE CustomerID = @CustomerID AND
DATEDIFF(mi, LastUpdatedAt, GETDATE()) < @MinsBack)
IF (@Count = 1)
SELECT 'Ok: 1 record in CustomerProduct table'
ELSE
SELECT 'ERROR: Expected 1 record in CustomerProduct table, but found ' + CONVERT(varchar(3), @Count) + ' records.'
SELECT *FROM Customer where customerID = @CustomerID
END
結合其他答案只需要處理兩個輸出。 –