Skip to content

Instantly share code, notes, and snippets.

@jonsagara
Created September 12, 2023 21:46
Show Gist options
  • Save jonsagara/7e7672870802192ea01d1fffaa95941a to your computer and use it in GitHub Desktop.
Save jonsagara/7e7672870802192ea01d1fffaa95941a to your computer and use it in GitHub Desktop.
Dapper unbuffered query
var sql = """
SELECT
*
FROM
Widgets
WHERE
AccountId = @AccountId
ORDER BY
SomeField
""";
using (var conn = new SqlConnection(config.GetConnectionString("MyConnectionString")))
{
await foreach (var widget in conn.QueryUnbufferedAsync<WidgetModel>(query, new { accountId }))
{
// Do something with each record
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment