I have been using Dapper as my ORM for my .NET Core Web Api.
When using Dapper to query a stored procedure from my database with one parameter, it works exactly as expected. When I add more than one parameter, it does not return anything back to my datamodel like it should.
I suspect this has to do either with my syntax or the way I am structuring the query. The stored procedure I am using below works as expected when executed inside a SSMS query window.
Here is my method containing the Dapper Query in my DAL:
public List<Players> C_GetAllActivePlayersInSport(int orgID, int sportID)
{
using (IDbConnection db = new SqlConnection(_connectionString))
{
var returnedData = db.Query<Players>("dbo.spPlayers_GetAllActivePlayers_by_Sport @orgID, @sportID", new { orgID = orgID, sportID = sportID }).ToList();
return returnedData;
}
}
The values passed in make it to the method and query above, but after the query executes, it returns a list with a count of 0.
Any help would be greatly appreciated!
Try:
var returnedData = db.Query<Players>(
"dbo.spPlayers_GetAllActivePlayers_by_Sport",
new { orgID, sportID }, commandType: CommandType.StoredProcedure).ToList();
(note: .AsList()
would be marginally preferable)
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.