简体   繁体   中英

Operand type clash: int is incompatible with uniqueidentifier c# Dapper.Net

I've tried many solutions on stackoverflow yet not one gave me a solution, I have the following query, which passes in three parameters

  using (var sqlCon = new SqlConnection(Database.ReturnDatabaseConnection()))
   {
     var p = new DynamicParameters();
     p.Add("@EmailAddress", emailAddress);
     p.Add("@UserId", SqlDbType.BigInt, direction: ParameterDirection.InputOutput);
     p.Add("@UniqueId", SqlDbType.UniqueIdentifier, direction: ParameterDirection.InputOutput);

     var t = sqlCon.Execute("RequestPasswordReset", p, commandType: CommandType.StoredProcedure);

     var b = p.Get<Int64>("@UserId");
     var c = p.Get<Guid>("@UniqueId");
    }

which calls the following stored procedure

ALTER PROCEDURE RequestPasswordReset
@EmailAddress varchar(320),
@UserId bigint output,
@UniqueId UniqueIdentifier output
AS
BEGIN

SET NOCOUNT ON;

SET @UserId = (Select ISNULL(Id, NULL) from [User].[User_Profile] where EmailAddress = @EmailAddress and ProfileStatus <> 5)

IF @UserId is not null 
BEGIN 

       SET @UniqueId = NEWID()    

       INSERT INTO [Reset].[PasswordReset] 
              (UserId, UniqueId, 
               DateRequested, DateCompleted)

       VALUES 
              (@UserId, @UniqueId, SYSDATETIME(), NULL)


END  

If the user exists I will return the userId (bigint) and the uniqueId (UniqueIdentifier)

when I get to the following line in my C# project

sqlCon.Execute("RequestPasswordReset", p, commandType: CommandType.StoredProcedure);

I get the error message written as the title of this question, can someone explain to me what I'm doing wrong here?

The table structure is as follows:

CREATE TABLE [Reset].[PasswordReset](
[Id] [bigint] IDENTITY(1,1) NOT NULL,
[UserId] [bigint] NOT NULL,
[UniqueId] [uniqueidentifier] NOT NULL,
[DateRequested] [datetime] NOT NULL,
[DateCompleted] [datetime] NULL,
CONSTRAINT [PK_Reset]].[PasswordReset] PRIMARY KEY CLUSTERED 
(
[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

User Profile table as requested

CREATE TABLE [User].[User_Profile](
[Id] [bigint] IDENTITY(1,1) NOT NULL,
[UniqueId] [uniqueidentifier] NOT NULL,
[Username] [varchar](25) NOT NULL,
[EmailAddress] [varchar](320) NOT NULL,
[Password] [varchar](200) NOT NULL,
[ProfileStatus] [int] NOT NULL,
CONSTRAINT [PK_User.User_Profile] PRIMARY KEY CLUSTERED 
(
[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

I was stuck with the same problem. Try this. It solved my issue.

p.Add("@UserId",null,dbType: DbType.BigInt, direction: ParameterDirection.Output);
p.Add("@UniqueId",null,dbType: DbType.Guid, direction: ParameterDirection.Output,size:40);

I guess the Add method expects value as the second parameter, in case of output as a parameter as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM