Dapper TVP Behavior and SQL Server Monitoring Overhead
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
Hi
I’m reaching out to ask for your advice regarding how Dapper sends Table-Valued Parameters (TVPs) to SQL Server and how that appears in monitoring tools such as Extended Events.
In my project, I have defined a TVP as follows:
CREATE TYPE dbo.UserDefinedParameters AS TABLE (
Id INT,
Value1 INT,
Value2 INT,
Value3 INT
)
Dapper parameters on call store procedure command
var searchParameters = new
{
SearchParams = table.AsTableValuedParameter("dbo.UserDefinedParameters"),
OtherParam01 = 10,
OtherParam02 = 20,
};
Everything works correctly, but our database team raised a concern regarding how this call is logged in Extended Events. Specifically, they noticed that each row in the TVP is being sent as a separate INSERT INTO statement, like this:
DECLARE @p1 dbo.UserDefinedParameters
INSERT INTO @p1 VALUES (1, 1, 1388, NULL)
INSERT INTO @p1 VALUES (2, 1, 1388, 603)
-- potentially hundreds more...
EXEC dbo.Search
@SearchParams = @p1,
@OtherParam01 = NULL,
@OtherParam02 = NULL,
...
My questions are:
Is this the expected behavior from Dapper when sending TVPs?
Is there a way to batch these values or reduce the number of INSERT statements?
Have you seen this being a real issue in practice, and would you recommend any workaround or tuning?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the stored procedure call using Dapper's AsTableValuedParameter and inspect the resulting SQL Server Extended Events output. Compare the observed per-row INSERT statements with the expected TVP behavior and document whether batching or a practical workaround is available; the issue names no repository files or tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100