0

由于当我尝试从返回多个结果集的 mvc 项目运行存储过程时出现错误错误,我决定像这样拆分我的 Sp:我正在使用实体框架数据库优先方法。

这是我原来的存储过程:

  Create PROCEDURE [dbo].[uspMarket_test]
@UserID INT OUTPUT,
@Session VARCHAR(36)
  AS
  BEGIN
SET NOCOUNT ON;

    SELECT TOP 1
        FirstName, LastName, grant
    FROM dbo.test_Users AS U
    WHERE
       U.userID = @UserID 
       AND CAST (U.userHashKey as varchar(36)) = @Session;

    select
       GS.Account, GSA.Permissions
    from user_name GS 
    Inner join user_name_Apps GSA on GS.ID = GSA.ID
    where GS.UserID = @UserID

    UPDATE dbo.test_Users 
    SET grant = 0
    WHERE
     userID = @UserID
     ;

    END

现在我把它分成两个这样的:

   USE [Tracker]
   GO
  SET ANSI_NULLS ON
   GO

   SET QUOTED_IDENTIFIER ON
  GO

   Create PROCEDURE [dbo].[Market_Scope]
@UserID INT OUTPUT
  AS
    BEGIN
SET NOCOUNT ON;

SELECT TOP 1

       GS.Account, GSA.Permissions
     from user_name GS 
     Inner join user_name_Apps GSA on GS.ID = GSA.ID
       where GS.UserID = @UserID
 ;
          END
           GO

第二个SP是:

    USE [Tracker]
   GO
   SET ANSI_NULLS ON
   GO

   SET QUOTED_IDENTIFIER ON
   GO

   Create PROCEDURE [dbo].[Market_Users]
          @UserID INT OUTPUT,
        @Session VARCHAR(36)
        SELECT TOP 1
       FirstName, LastName, grant
        FROM dbo.test_Users AS U
     WHERE
      U.userID = @UserID 
     AND CAST (U.userHashKey as varchar(36)) = @Session;
    UPDATE dbo.test_Users 
     SET grant = 0
    WHERE
    userID = @UserID
     ;

    END
     Go

现在我在课堂上这样称呼这两个 SP:

     public void permissions(string sess)
    {
        using (var ctx2 = new Tracker_Entities())
        {  
       ctx2.uspMarket_Users(new ObjectParameter("UserID", typeof(int)), sess);
       ctx2.uspMarket_list(new ObjectParameter("UserID",typeof(int)));
       ctx2.SaveChanges();
        }
      }

这就是我在控制器中调用的方式:

  public ActionResult Index(string sess)
    {

        var permissions = new Accept();
        permissions.permissions(sess);



        return View();
     }

因为两个 SP 都只是选择我所做的记录,所以我将虚拟数据填充到我的 user_name_apps 表中。那么我如何在前端检查这个 SP 是否正确执行?我可以在我的 sql server 中执行,它在那里工作正常。但我想确保我正确调用我的 SP。那么我该怎么做呢?

4

0 回答 0