执行时,我无法从存储过程中读取值。
这是我的存储过程
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);
}
抛出异常
数据阅读器与指定的'TestModel.SaveInvitation_Result'不兼容。类型为“InvitationGUID”的成员在数据读取器中没有相应名称的相应列。
我创建了一个复杂类型,即SaveUserRegistration_Result
,并导入了一个返回类型为SaveInvitation
的函数SaveUserRegistration_Result
。
如何解决上述异常?存储过程有变化吗?
屏幕截图
答案 0 :(得分:1)
它给你这个错误,因为你实际上并没有SELECT
结果。如果您在 的末尾添加了一行 ,例如:
SELECT @InvitationGUID AS InvitationGUID
它应该对你有用。