ZZZ Code AI
Report Issues
Suggest Features
Login
Dapper Tools
Chat
Code Explain
Seed Data Generator
Sql Generator
Stored Procedure Generator
Entity to Table Converter
Table to Entity Converter
Sql Injection Detector
More Tools
How to retrieve multiple rows returned by a stored procedure in Dapper?
<p>To retrieve multiple rows returned by a <a href="https://www.learndapper.com/stored-procedures">stored procedure</a>, you need to specify the stored procedure name in the command text and specify the command type to <code>CommandType.StoredProcedure</code>.</p> <ol> <li>First, create your stored procedure:</li> </ol> <pre><code class="language-sql">CREATE PROCEDURE MyStoredProcedure AS BEGIN SELECT * FROM Customer END </code></pre> <ol start="2"> <li>Map returned data to an anonymous type or a strongly typed object:</li> </ol> <pre><code class="language-csharp">using (var connection = new SqlConnection("connectionString")) { var result = connection.Query("MyStoredProcedure", commandType: CommandType.StoredProcedure).ToList(); } </code></pre> <pre><code class="language-csharp">public class Customer { public int CustomerID { get; set; } public string Name { get; set; } // Add other properties as needed, to match all columns returned by the stored procedure } using (var connection = new SqlConnection("connectionString")) { var result = connection.Query<Customer>("MyStoredProcedure", commandType: CommandType.StoredProcedure).ToList(); } </code></pre>
Sponsored by
Dapper Plus
This field is required
A text with a minimum of 10 characters is required
Send
Legal & Licensing
Answer generated by AI may produce inaccurate information about code, people, facts, and more.
Advertising Break!
5
seconds left
Did you know...
That you can now sponsor this project on
GitHub
?