- What Dapper method can be used to execute a stored procedure that returns no results?
Execute
- What Dapper method can be used to read a single record of data where the record is guaranteed to exist?
QueryFirst
- What Dapper method can be used to read a collection of records?
Query
- What is wrong with the following statement that calls the Dapper Query method?
return connection.Query<BuildingGetManyResponse>(
@"EXEC dbo.Building_GetMany_BySearch
@Search = @Search",
new { Criteria = "Fred"}
);
The query expects a parameter called Search but we have passed it a parameter called Criteria. So, Dapper won't be able to map the SQL parameter.
- We have the following stored procedure:
CREATE PROC dbo.Building_GetMany
AS
BEGIN
SET NOCOUNT ON
SELECT BuildingId, Name
FROM dbo.Building
END
We have the following statement that calls the Dapper Query method:
return connection.Query<BuildingGetManyResponse>(
"EXEC dbo.Building_GetMany"
);
We also have the following data model that is referenced in the preceding statement:
public class BuildingGetManyResponse
{
public int Id{ get; set; }
public string Name { get; set; }
}
When our app is run, we find that the Id property within the BuildingGetManyResponse class instances is not populated. Can you spot the problem?
The problem is that the stored procedure returns a field called BuildingId, which won't automatically get mapped to the Id property in the class because the names are different.
- Can DbUp be used to deploy new reference data within a table?
Yes! DbUp can execute any SQL script.