You need to tell it the command type: make sure there's a commandType: CommandType.StoredProcedure
in the dapper call. Otherwise, it is simply executing the text command:
spMyStoredProcedure
(with some unused parameters in the ambient context). This is legal TSQL, and attempts to call spMyStoredProcedure
without passing parameters - the same as if you put spMyStoredProcedure
into SSMS and press f5.
Also, if your parameters are fixed, I would actually suggest just using:
var param = new { somethingId };
or even just inline it completely:
var result = repository.Exec<Something>(SomethingEnum.spMyStoredProcedure,
new { somethingId }, commandType: CommandType.StoredProcedure);
(note: if your Exec<T>
method only ever handles stored procedures, you could move the commandType
internal to the method - or you could make it an optional parameter that defaults to CommandType.StoredProcedure
)