Required parameters, Dapper and System.Data.SqlClient.SqlException

I use Dapper to call a stored procedure that has a required @idProject parameter

this is my piece of code:

 using (var c = _connectionWrapper.DbConnection) { var result = c.Query<Xxx>("dbo.xxx_xxxGetPage", new { @idProject = 1 }).AsList(); return result; } 

Should work, but throw an exception:

An exception of type "System.Data.SqlClient.SqlException" occurred in System.Data.dll, but was not processed in the user code.

Additional information: Procedure or function 'xxxGetPage' expects parameter '@idProject', which was not provided.

Why?

+5
source share
2 answers

I think you are missing CommandType .

 using (var c = _connectionWrapper.DbConnection) { var result = c.Query<Xxx>("dbo.xxx_xxxGetPage", new { idProject = 1 }, commandType: CommandType.StoredProcedure).AsList(); return result; } 

By default, dapper uses text.

https://github.com/StackExchange/dapper-dot-net

+3
source

try the following:

 var result = c.Query<Xxx>("dbo.xxx_xxxGetPage", new {1}).AsList(); 
0
source

Source: https://habr.com/ru/post/1233030/


All Articles