1

执行时我无法从存储过程中读取值。

这是我的存储过程

ALTER Procedure [dbo].[SaveInvitation]
(
    @InvitationID INT OUTPUT,
    @UserID INT,
    @Email NCHAR(100),
    @InvitationGUID  UNIQUEIDENTIFIER OUTPUT
)
AS
BEGIN
SET NOCOUNT ON;

BEGIN TRY
    IF @UserID = -1
        BEGIN
            SET @UserID = NULL
        END

    IF NOT EXISTS (SELECT 1 FROM Invitations WHERE LTRIM(RTRIM(Email)) = LTRIM(RTRIM(@Email)))
        BEGIN
            INSERT INTO Invitations (UserID,
                    Email,
                    CreateDate)
            VALUES (@UserID,
                    @Email,
                    GETDATE())

            -- GET NEWLY INSERTED INVITATIONS ID
            SET @InvitationID = IDENT_CURRENT('Invitations')

            -- GET GUID FROM INVITATION ID
            SELECT  @InvitationGUID = InvitationGUID
            FROM    Invitations
            WHERE   InvitationID = @InvitationID
        END
    ELSE
        BEGIN
            RAISERROR('ALREADY_INVITATED', 16, 127)
        END
END TRY
BEGIN CATCH
    IF @@TRANCOUNT > 0
        BEGIN
            ROLLBACK
        END
    EXEC ThrowError
END CATCH
END

我正在从这个函数执行这个过程

我的DataBaseModel.Designer.cs

public ObjectResult<SaveInvitation_Result> SaveInvitation(ObjectParameter invitationID, Nullable<global::System.Int32> userID, global::System.String email, ObjectParameter invitationGUID)
    {
        ObjectParameter userIDParameter;
        if (userID.HasValue)
        {
            userIDParameter = new ObjectParameter("UserID", userID);
        }
        else
        {
            userIDParameter = new ObjectParameter("UserID", typeof(global::System.Int32));
        }

        ObjectParameter emailParameter;
        if (email != null)
        {
            emailParameter = new ObjectParameter("Email", email);
        }
        else
        {
            emailParameter = new ObjectParameter("Email", typeof(global::System.String));
        }

        return base.ExecuteFunction<SaveInvitation_Result>("SaveInvitation", invitationID, userIDParameter, emailParameter, invitationGUID);
    }

它抛出一个异常

数据读取器与指定的“Te​​stModel.SaveInvitation_Result”不兼容。类型的成员“InvitationGUID”在数据读取器中没有同名的对应列。

我创建了一个复杂类型,即SaveUserRegistration_Result并导入了一个SaveInvitation返回类型的 函数SaveUserRegistration_Result

如何解决上述异常?存储过程有什么变化吗?

截屏

在此处输入图像描述

4

1 回答 1

1

它给你这个错误是因为你实际上并没有SELECT返回结果。例如,如果您在程序的末尾添加了一行:

SELECT  @InvitationGUID AS InvitationGUID

它应该适合你。

于 2012-12-26T13:12:55.500 回答